gh-92647: [Enum] use final status to determine lookup or create by ethanfurman · Pull Request #99500 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Lib/enum.py
21 changes: 18 additions & 3 deletions Lib/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,21 @@ def test_programmatic_function_type_from_subclass_with_start(self):
self.assertIn(e, MinorEnum)
self.assertIs(type(e), MinorEnum)

def test_programmatic_function_is_value_call(self):
class TwoPart(Enum):
ONE = 1, 1.0
TWO = 2, 2.0
THREE = 3, 3.0
self.assertRaisesRegex(ValueError, '1 is not a valid .*TwoPart', TwoPart, 1)
self.assertIs(TwoPart((1, 1.0)), TwoPart.ONE)
self.assertIs(TwoPart(1, 1.0), TwoPart.ONE)
class ThreePart(Enum):
ONE = 1, 1.0, 'one'
TWO = 2, 2.0, 'two'
THREE = 3, 3.0, 'three'
self.assertIs(ThreePart((3, 3.0, 'three')), ThreePart.THREE)
self.assertIs(ThreePart(3, 3.0, 'three'), ThreePart.THREE)

def test_intenum_from_bytes(self):
self.assertIs(IntStooges.from_bytes(b'\x00\x03', 'big'), IntStooges.MOE)
with self.assertRaises(ValueError):
Expand Down Expand Up @@ -1463,7 +1478,7 @@ class MoreColor(Color):
class EvenMoreColor(Color, IntEnum):
chartruese = 7
#
with self.assertRaisesRegex(TypeError, "<enum .Foo.> cannot extend <enum .Color.>"):
with self.assertRaisesRegex(ValueError, "\(.Foo., \(.pink., .black.\)\) is not a valid .*Color"):
Color('Foo', ('pink', 'black'))

def test_exclude_methods(self):
Expand Down Expand Up @@ -4181,7 +4196,7 @@ class TestEnumTypeSubclassing(unittest.TestCase):
Help on class Color in module %s:

class Color(enum.Enum)
| Color(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
| Color(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)
|
| Method resolution order:
| Color
Expand Down Expand Up @@ -4237,7 +4252,7 @@ class Color(enum.Enum)
Help on class Color in module %s:

class Color(enum.Enum)
| Color(value, names=None, *, module=None, qualname=None, type=None, start=1)
| Color(value, names=None, *values, module=None, qualname=None, type=None, start=1)
|
| Method resolution order:
| Color
Expand Down