Revert "bpo-38659: [Enum] add _simple_enum decorator (GH-25285)" (GH-… · python/cpython@503cdc7 · GitHub
Skip to content

Commit 503cdc7

Browse files
authored
Revert "bpo-38659: [Enum] add _simple_enum decorator (GH-25285)" (GH-25476)
This reverts commit dbac8f4.
1 parent dbac8f4 commit 503cdc7

20 files changed

Lines changed: 34 additions & 871 deletions

Doc/library/enum.rst

Lines changed: 1 addition & 0 deletions

Lib/ast.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import sys
2828
from _ast import *
2929
from contextlib import contextmanager, nullcontext
30-
from enum import IntEnum, auto, _simple_enum
30+
from enum import IntEnum, auto
3131

3232

3333
def parse(source, filename='<unknown>', mode='exec', *,
@@ -636,8 +636,7 @@ class Param(expr_context):
636636
# We unparse those infinities to INFSTR.
637637
_INFSTR = "1e" + repr(sys.float_info.max_10_exp + 1)
638638

639-
@_simple_enum(IntEnum)
640-
class _Precedence:
639+
class _Precedence(IntEnum):
641640
"""Precedence table that originated from python grammar."""
642641

643642
TUPLE = auto()

Lib/enum.py

Lines changed: 7 additions & 319 deletions
Large diffs are not rendered by default.

Lib/http/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
from enum import IntEnum, _simple_enum
1+
from enum import IntEnum
22

33
__all__ = ['HTTPStatus']
44

5-
6-
@_simple_enum(IntEnum)
7-
class HTTPStatus:
5+
class HTTPStatus(IntEnum):
86
"""HTTP status codes and reason phrases
97
108
Status codes from the following RFCs are all observed:

Lib/pstats.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@
2626
import marshal
2727
import re
2828

29-
from enum import StrEnum, _simple_enum
29+
from enum import Enum
3030
from functools import cmp_to_key
3131
from dataclasses import dataclass
3232
from typing import Dict
3333

3434
__all__ = ["Stats", "SortKey", "FunctionProfile", "StatsProfile"]
3535

36-
@_simple_enum(StrEnum)
37-
class SortKey:
36+
class SortKey(str, Enum):
3837
CALLS = 'calls', 'ncalls'
3938
CUMULATIVE = 'cumulative', 'cumtime'
4039
FILENAME = 'filename', 'module'

Lib/re.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@
143143
__version__ = "2.2.1"
144144

145145
@enum.global_enum
146-
@enum._simple_enum(enum.IntFlag, boundary=enum.KEEP)
147-
class RegexFlag:
146+
class RegexFlag(enum.IntFlag, boundary=enum.KEEP):
148147
ASCII = A = sre_compile.SRE_FLAG_ASCII # assume ascii "locale"
149148
IGNORECASE = I = sre_compile.SRE_FLAG_IGNORECASE # ignore case
150149
LOCALE = L = sre_compile.SRE_FLAG_LOCALE # assume current 8-bit locale

Lib/ssl.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
import os
9595
from collections import namedtuple
9696
from enum import Enum as _Enum, IntEnum as _IntEnum, IntFlag as _IntFlag
97-
from enum import _simple_enum, _test_simple_enum
9897

9998
import _ssl # if we can't import it, let the error propagate
10099

@@ -156,8 +155,7 @@
156155
_SSLv2_IF_EXISTS = getattr(_SSLMethod, 'PROTOCOL_SSLv2', None)
157156

158157

159-
@_simple_enum(_IntEnum)
160-
class TLSVersion:
158+
class TLSVersion(_IntEnum):
161159
MINIMUM_SUPPORTED = _ssl.PROTO_MINIMUM_SUPPORTED
162160
SSLv3 = _ssl.PROTO_SSLv3
163161
TLSv1 = _ssl.PROTO_TLSv1
@@ -167,8 +165,7 @@ class TLSVersion:
167165
MAXIMUM_SUPPORTED = _ssl.PROTO_MAXIMUM_SUPPORTED
168166

169167

170-
@_simple_enum(_IntEnum)
171-
class _TLSContentType:
168+
class _TLSContentType(_IntEnum):
172169
"""Content types (record layer)
173170
174171
See RFC 8446, section B.1
@@ -182,8 +179,7 @@ class _TLSContentType:
182179
INNER_CONTENT_TYPE = 0x101
183180

184181

185-
@_simple_enum(_IntEnum)
186-
class _TLSAlertType:
182+
class _TLSAlertType(_IntEnum):
187183
"""Alert types for TLSContentType.ALERT messages
188184
189185
See RFC 8466, section B.2
@@ -224,8 +220,7 @@ class _TLSAlertType:
224220
NO_APPLICATION_PROTOCOL = 120
225221

226222

227-
@_simple_enum(_IntEnum)
228-
class _TLSMessageType:
223+
class _TLSMessageType(_IntEnum):
229224
"""Message types (handshake protocol)
230225
231226
See RFC 8446, section B.3

Lib/test/test_ast.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import ast
22
import builtins
33
import dis
4-
import enum
54
import os
65
import sys
76
import types
@@ -699,35 +698,6 @@ def test_constant_as_name(self):
699698
with self.assertRaisesRegex(ValueError, f"Name node can't be used with '{constant}' constant"):
700699
compile(expr, "<test>", "eval")
701700

702-
def test_precedence_enum(self):
703-
class _Precedence(enum.IntEnum):
704-
"""Precedence table that originated from python grammar."""
705-
TUPLE = enum.auto()
706-
YIELD = enum.auto() # 'yield', 'yield from'
707-
TEST = enum.auto() # 'if'-'else', 'lambda'
708-
OR = enum.auto() # 'or'
709-
AND = enum.auto() # 'and'
710-
NOT = enum.auto() # 'not'
711-
CMP = enum.auto() # '<', '>', '==', '>=', '<=', '!=',
712-
# 'in', 'not in', 'is', 'is not'
713-
EXPR = enum.auto()
714-
BOR = EXPR # '|'
715-
BXOR = enum.auto() # '^'
716-
BAND = enum.auto() # '&'
717-
SHIFT = enum.auto() # '<<', '>>'
718-
ARITH = enum.auto() # '+', '-'
719-
TERM = enum.auto() # '*', '@', '/', '%', '//'
720-
FACTOR = enum.auto() # unary '+', '-', '~'
721-
POWER = enum.auto() # '**'
722-
AWAIT = enum.auto() # 'await'
723-
ATOM = enum.auto()
724-
def next(self):
725-
try:
726-
return self.__class__(self + 1)
727-
except ValueError:
728-
return self
729-
enum._test_simple_enum(_Precedence, ast._Precedence)
730-
731701

732702
class ASTHelpers_Test(unittest.TestCase):
733703
maxDiff = None

Lib/test/test_enum.py

Lines changed: 5 additions & 56 deletions

0 commit comments

Comments
 (0)