Skip to content

Commit 42a64c0

Browse files
authored
Revert "bpo-40066: [Enum] update str() and format() output (GH-30582)" (GH-30632)
This reverts commit acf7403.
1 parent 7f4b69b commit 42a64c0

14 files changed

+2030
-2096
lines changed

Doc/howto/enum.rst

+146-126
Large diffs are not rendered by default.

Doc/library/enum.rst

+92-173
Large diffs are not rendered by default.

Doc/library/ssl.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,7 @@ to speed up repeated connections from the same clients.
20702070
:attr:`SSLContext.verify_flags` returns :class:`VerifyFlags` flags:
20712071

20722072
>>> ssl.create_default_context().verify_flags # doctest: +SKIP
2073-
<VerifyFlags.VERIFY_X509_TRUSTED_FIRST: 32768>
2073+
ssl.VERIFY_X509_TRUSTED_FIRST
20742074

20752075
.. attribute:: SSLContext.verify_mode
20762076

@@ -2082,7 +2082,7 @@ to speed up repeated connections from the same clients.
20822082
:attr:`SSLContext.verify_mode` returns :class:`VerifyMode` enum:
20832083

20842084
>>> ssl.create_default_context().verify_mode
2085-
<VerifyMode.CERT_REQUIRED: 2>
2085+
ssl.CERT_REQUIRED
20862086

20872087
.. index:: single: certificates
20882088

Lib/enum.py

+232-371
Large diffs are not rendered by default.

Lib/inspect.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -2567,28 +2567,30 @@ class _empty:
25672567

25682568

25692569
class _ParameterKind(enum.IntEnum):
2570-
POSITIONAL_ONLY = 'positional-only'
2571-
POSITIONAL_OR_KEYWORD = 'positional or keyword'
2572-
VAR_POSITIONAL = 'variadic positional'
2573-
KEYWORD_ONLY = 'keyword-only'
2574-
VAR_KEYWORD = 'variadic keyword'
2575-
2576-
def __new__(cls, description):
2577-
value = len(cls.__members__)
2578-
member = int.__new__(cls, value)
2579-
member._value_ = value
2580-
member.description = description
2581-
return member
2570+
POSITIONAL_ONLY = 0
2571+
POSITIONAL_OR_KEYWORD = 1
2572+
VAR_POSITIONAL = 2
2573+
KEYWORD_ONLY = 3
2574+
VAR_KEYWORD = 4
25822575

2583-
def __str__(self):
2584-
return self.name
2576+
@property
2577+
def description(self):
2578+
return _PARAM_NAME_MAPPING[self]
25852579

25862580
_POSITIONAL_ONLY = _ParameterKind.POSITIONAL_ONLY
25872581
_POSITIONAL_OR_KEYWORD = _ParameterKind.POSITIONAL_OR_KEYWORD
25882582
_VAR_POSITIONAL = _ParameterKind.VAR_POSITIONAL
25892583
_KEYWORD_ONLY = _ParameterKind.KEYWORD_ONLY
25902584
_VAR_KEYWORD = _ParameterKind.VAR_KEYWORD
25912585

2586+
_PARAM_NAME_MAPPING = {
2587+
_POSITIONAL_ONLY: 'positional-only',
2588+
_POSITIONAL_OR_KEYWORD: 'positional or keyword',
2589+
_VAR_POSITIONAL: 'variadic positional',
2590+
_KEYWORD_ONLY: 'keyword-only',
2591+
_VAR_KEYWORD: 'variadic keyword'
2592+
}
2593+
25922594

25932595
class Parameter:
25942596
"""Represents a parameter in a function signature.

Lib/plistlib.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@
6161
from xml.parsers.expat import ParserCreate
6262

6363

64-
PlistFormat = enum.Enum('PlistFormat', 'FMT_XML FMT_BINARY', module=__name__)
65-
globals().update(PlistFormat.__members__)
64+
PlistFormat = enum.global_enum(enum.Enum('PlistFormat', 'FMT_XML FMT_BINARY', module=__name__))
6665

6766

6867
class UID:

Lib/re.py

-2
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ class RegexFlag:
155155
# sre extensions (experimental, don't rely on these)
156156
TEMPLATE = T = sre_compile.SRE_FLAG_TEMPLATE # disable backtracking
157157
DEBUG = sre_compile.SRE_FLAG_DEBUG # dump pattern after compilation
158-
__str__ = object.__str__
159-
_numeric_repr_ = hex
160158

161159
# sre exception
162160
error = sre_compile.error

Lib/ssl.py

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
)
120120
from _ssl import _DEFAULT_CIPHERS, _OPENSSL_API_VERSION
121121

122+
122123
_IntEnum._convert_(
123124
'_SSLMethod', __name__,
124125
lambda name: name.startswith('PROTOCOL_') and name != 'PROTOCOL_SSLv23',

0 commit comments

Comments
 (0)