◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
1 change: 0 additions & 1 deletion Doc/library/enum.rst
Original file line number Diff line number Diff line change
@@ -621,4 +621,3 @@ Utilites and Decorators
Traceback (most recent call last):
...
ValueError: duplicate values found in <enum 'Mistake'>: FOUR -> THREE

5 changes: 3 additions & 2 deletions Lib/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import sys
from _ast import *
from contextlib import contextmanager, nullcontext
from enum import IntEnum, auto


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

class _Precedence(IntEnum):
"""Precedence table that originated from python grammar."""

TUPLE = auto()
Expand Down
325 changes: 318 additions & 7 deletions Lib/enum.py
6 changes: 4 additions & 2 deletions Lib/http/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from enum import IntEnum

__all__ = ['HTTPStatus']

class HTTPStatus(IntEnum):
"""HTTP status codes and reason phrases

Status codes from the following RFCs are all observed:
Expand Down
5 changes: 3 additions & 2 deletions Lib/pstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
import marshal
import re

from enum import Enum
from functools import cmp_to_key
from dataclasses import dataclass
from typing import Dict

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

class SortKey(str, Enum):
CALLS = 'calls', 'ncalls'
CUMULATIVE = 'cumulative', 'cumtime'
FILENAME = 'filename', 'module'
Expand Down
3 changes: 2 additions & 1 deletion Lib/re.py
Original file line number Diff line number Diff line change
@@ -143,7 +143,8 @@
__version__ = "2.2.1"

@enum.global_enum
class RegexFlag(enum.IntFlag, boundary=enum.KEEP):
ASCII = A = sre_compile.SRE_FLAG_ASCII # assume ascii "locale"
IGNORECASE = I = sre_compile.SRE_FLAG_IGNORECASE # ignore case
LOCALE = L = sre_compile.SRE_FLAG_LOCALE # assume current 8-bit locale
Expand Down
13 changes: 9 additions & 4 deletions Lib/ssl.py
Original file line number Diff line number Diff line change
@@ -94,6 +94,7 @@
import os
from collections import namedtuple
from enum import Enum as _Enum, IntEnum as _IntEnum, IntFlag as _IntFlag

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

Expand Down Expand Up @@ -155,7 +156,8 @@
_SSLv2_IF_EXISTS = getattr(_SSLMethod, 'PROTOCOL_SSLv2', None)


class TLSVersion(_IntEnum):
MINIMUM_SUPPORTED = _ssl.PROTO_MINIMUM_SUPPORTED
SSLv3 = _ssl.PROTO_SSLv3
TLSv1 = _ssl.PROTO_TLSv1
@@ -165,7 +167,8 @@ class TLSVersion(_IntEnum):
MAXIMUM_SUPPORTED = _ssl.PROTO_MAXIMUM_SUPPORTED


class _TLSContentType(_IntEnum):
"""Content types (record layer)

See RFC 8446, section B.1
Expand All @@ -179,7 +182,8 @@ class _TLSContentType(_IntEnum):
INNER_CONTENT_TYPE = 0x101


class _TLSAlertType(_IntEnum):
"""Alert types for TLSContentType.ALERT messages

See RFC 8466, section B.2
Expand Down Expand Up @@ -220,7 +224,8 @@ class _TLSAlertType(_IntEnum):
NO_APPLICATION_PROTOCOL = 120


class _TLSMessageType(_IntEnum):
"""Message types (handshake protocol)

See RFC 8446, section B.3
Expand Down
30 changes: 30 additions & 0 deletions Lib/test/test_ast.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ast
import builtins
import dis
import os
import sys
import types
Expand Up @@ -698,6 +699,35 @@ def test_constant_as_name(self):
with self.assertRaisesRegex(ValueError, f"Name node can't be used with '{constant}' constant"):
compile(expr, "<test>", "eval")


class ASTHelpers_Test(unittest.TestCase):
maxDiff = None
Expand Down
61 changes: 56 additions & 5 deletions Lib/test/test_enum.py
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
import threading
from collections import OrderedDict
from enum import Enum, IntEnum, StrEnum, EnumType, Flag, IntFlag, unique, auto
from enum import STRICT, CONFORM, EJECT, KEEP
from io import StringIO
from pickle import dumps, loads, PicklingError, HIGHEST_PROTOCOL
from test import support
Expand Down Expand Up @@ -2511,10 +2511,13 @@ class Bizarre(Flag, boundary=KEEP):
d = 6
#
self.assertRaisesRegex(ValueError, 'invalid value: 7', Iron, 7)
self.assertIs(Water(7), Water.ONE|Water.TWO)
self.assertIs(Water(~9), Water.TWO)
self.assertEqual(Space(7), 7)
self.assertTrue(type(Space(7)) is int)
self.assertEqual(list(Bizarre), [Bizarre.c])
self.assertIs(Bizarre(3), Bizarre.b)
self.assertIs(Bizarre(6), Bizarre.d)
Expand Down Expand Up @@ -3053,16 +3056,20 @@ class Space(IntFlag, boundary=EJECT):
EIGHT = 8
self.assertIs(Space._boundary_, EJECT)
#
class Bizarre(IntFlag, boundary=KEEP):
b = 3
c = 4
d = 6
#
self.assertRaisesRegex(ValueError, 'invalid value: 5', Iron, 5)
self.assertIs(Water(7), Water.ONE|Water.TWO)
self.assertIs(Water(~9), Water.TWO)
self.assertEqual(Space(7), 7)
self.assertTrue(type(Space(7)) is int)
self.assertEqual(list(Bizarre), [Bizarre.c])
self.assertIs(Bizarre(3), Bizarre.b)
self.assertIs(Bizarre(6), Bizarre.d)
Expand Up @@ -3577,6 +3584,41 @@ def test_inspect_classify_class_attrs(self):
if failed:
self.fail("result does not equal expected, see print above")


class MiscTestCase(unittest.TestCase):
def test__all__(self):
Expand All @@ -3592,6 +3634,13 @@ def test__all__(self):
CONVERT_TEST_NAME_E = 5
CONVERT_TEST_NAME_F = 5

class TestIntEnumConvert(unittest.TestCase):
def test_convert_value_lookup_priority(self):
test_type = enum.IntEnum._convert_(
Expand Down Expand Up @@ -3639,14 +3688,16 @@ def test_convert_raise(self):
filter=lambda x: x.startswith('CONVERT_TEST_'))

def test_convert_repr_and_str(self):
module = ('test.test_enum', '__main__')[__name__=='__main__']
test_type = enum.IntEnum._convert_(
'UnittestConvert',
module,
filter=lambda x: x.startswith('CONVERT_TEST_'))
self.assertEqual(repr(test_type.CONVERT_TEST_NAME_A), '%s.CONVERT_TEST_NAME_A' % module)
self.assertEqual(str(test_type.CONVERT_TEST_NAME_A), 'CONVERT_TEST_NAME_A')
self.assertEqual(format(test_type.CONVERT_TEST_NAME_A), '5')

# global names for StrEnum._convert_ test
CONVERT_STR_TEST_2 = 'goodbye'
Expand Down
Loading
Toggle all file notes Toggle all file annotations