mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
bpo-40066: Enum: modify repr()
and str()
(GH-22392)
* Enum: streamline repr() and str(); improve docs - repr() is now ``enum_class.member_name`` - stdlib global enums are ``module_name.member_name`` - str() is now ``member_name`` - add HOW-TO section for ``Enum`` - change main documentation to be an API reference
This commit is contained in:
parent
51a85ddce8
commit
b775106d94
19 changed files with 2225 additions and 1491 deletions
|
@ -1518,9 +1518,9 @@ class GeneralModuleTests(unittest.TestCase):
|
|||
infos = socket.getaddrinfo(HOST, 80, socket.AF_INET, socket.SOCK_STREAM)
|
||||
for family, type, _, _, _ in infos:
|
||||
self.assertEqual(family, socket.AF_INET)
|
||||
self.assertEqual(str(family), 'AddressFamily.AF_INET')
|
||||
self.assertEqual(str(family), 'AF_INET')
|
||||
self.assertEqual(type, socket.SOCK_STREAM)
|
||||
self.assertEqual(str(type), 'SocketKind.SOCK_STREAM')
|
||||
self.assertEqual(str(type), 'SOCK_STREAM')
|
||||
infos = socket.getaddrinfo(HOST, None, 0, socket.SOCK_STREAM)
|
||||
for _, socktype, _, _, _ in infos:
|
||||
self.assertEqual(socktype, socket.SOCK_STREAM)
|
||||
|
@ -1793,8 +1793,8 @@ class GeneralModuleTests(unittest.TestCase):
|
|||
# Make sure that the AF_* and SOCK_* constants have enum-like string
|
||||
# reprs.
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
self.assertEqual(str(s.family), 'AddressFamily.AF_INET')
|
||||
self.assertEqual(str(s.type), 'SocketKind.SOCK_STREAM')
|
||||
self.assertEqual(str(s.family), 'AF_INET')
|
||||
self.assertEqual(str(s.type), 'SOCK_STREAM')
|
||||
|
||||
def test_socket_consistent_sock_type(self):
|
||||
SOCK_NONBLOCK = getattr(socket, 'SOCK_NONBLOCK', 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue