Skip to content

Commit

Permalink
Revert "bpo-40066: [Enum] update str() and format() output (GH-30582)" (
Browse files Browse the repository at this point in the history
GH-30632)

This reverts commit acf7403.
  • Loading branch information
vstinner committed Jan 17, 2022
1 parent 7f4b69b commit 42a64c0
Show file tree
Hide file tree
Showing 14 changed files with 2,030 additions and 2,096 deletions.
272 changes: 146 additions & 126 deletions Doc/howto/enum.rst

Large diffs are not rendered by default.

265 changes: 92 additions & 173 deletions Doc/library/enum.rst

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Doc/library/ssl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2070,7 +2070,7 @@ to speed up repeated connections from the same clients.
:attr:`SSLContext.verify_flags` returns :class:`VerifyFlags` flags:

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

.. attribute:: SSLContext.verify_mode

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

>>> ssl.create_default_context().verify_mode
<VerifyMode.CERT_REQUIRED: 2>
ssl.CERT_REQUIRED

.. index:: single: certificates

Expand Down
603 changes: 232 additions & 371 deletions Lib/enum.py

Large diffs are not rendered by default.

30 changes: 16 additions & 14 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2567,28 +2567,30 @@ class _empty:


class _ParameterKind(enum.IntEnum):
POSITIONAL_ONLY = 'positional-only'
POSITIONAL_OR_KEYWORD = 'positional or keyword'
VAR_POSITIONAL = 'variadic positional'
KEYWORD_ONLY = 'keyword-only'
VAR_KEYWORD = 'variadic keyword'

def __new__(cls, description):
value = len(cls.__members__)
member = int.__new__(cls, value)
member._value_ = value
member.description = description
return member
POSITIONAL_ONLY = 0
POSITIONAL_OR_KEYWORD = 1
VAR_POSITIONAL = 2
KEYWORD_ONLY = 3
VAR_KEYWORD = 4

def __str__(self):
return self.name
@property
def description(self):
return _PARAM_NAME_MAPPING[self]

_POSITIONAL_ONLY = _ParameterKind.POSITIONAL_ONLY
_POSITIONAL_OR_KEYWORD = _ParameterKind.POSITIONAL_OR_KEYWORD
_VAR_POSITIONAL = _ParameterKind.VAR_POSITIONAL
_KEYWORD_ONLY = _ParameterKind.KEYWORD_ONLY
_VAR_KEYWORD = _ParameterKind.VAR_KEYWORD

_PARAM_NAME_MAPPING = {
_POSITIONAL_ONLY: 'positional-only',
_POSITIONAL_OR_KEYWORD: 'positional or keyword',
_VAR_POSITIONAL: 'variadic positional',
_KEYWORD_ONLY: 'keyword-only',
_VAR_KEYWORD: 'variadic keyword'
}


class Parameter:
"""Represents a parameter in a function signature.
Expand Down
3 changes: 1 addition & 2 deletions Lib/plistlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@
from xml.parsers.expat import ParserCreate


PlistFormat = enum.Enum('PlistFormat', 'FMT_XML FMT_BINARY', module=__name__)
globals().update(PlistFormat.__members__)
PlistFormat = enum.global_enum(enum.Enum('PlistFormat', 'FMT_XML FMT_BINARY', module=__name__))


class UID:
Expand Down
2 changes: 0 additions & 2 deletions Lib/re.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ class RegexFlag:
# sre extensions (experimental, don't rely on these)
TEMPLATE = T = sre_compile.SRE_FLAG_TEMPLATE # disable backtracking
DEBUG = sre_compile.SRE_FLAG_DEBUG # dump pattern after compilation
__str__ = object.__str__
_numeric_repr_ = hex

# sre exception
error = sre_compile.error
Expand Down
1 change: 1 addition & 0 deletions Lib/ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
)
from _ssl import _DEFAULT_CIPHERS, _OPENSSL_API_VERSION


_IntEnum._convert_(
'_SSLMethod', __name__,
lambda name: name.startswith('PROTOCOL_') and name != 'PROTOCOL_SSLv23',
Expand Down
Loading

0 comments on commit 42a64c0

Please sign in to comment.