Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
restore mention of dataclass
  • Loading branch information
ethanfurman committed Apr 13, 2023
commit faff581517e19529986b44577203fe55f6f9be10
4 changes: 2 additions & 2 deletions Lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ def _find_data_repr_(mcls, class_name, bases):

@classmethod
def _find_data_type_(mcls, class_name, bases):
# a datatype has a __new__ method, or a __dataclass_fields__ attribute
# a datatype has a __new__ method
data_types = set()
base_chain = set()
for chain in bases:
Expand All @@ -994,7 +994,7 @@ def _find_data_type_(mcls, class_name, bases):
if base._member_type_ is not object:
data_types.add(base._member_type_)
break
elif '__new__' in base.__dict__:
elif '__new__' in base.__dict__ or '__dataclass_fields__' in base.__dict__:
if isinstance(base, EnumType):
continue
data_types.add(candidate or base)
Expand Down
4 changes: 1 addition & 3 deletions Lib/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2667,8 +2667,6 @@ class Foo:
a: int
class Entries(Foo, Enum):
ENTRY1 = 1
self.assertEqual(repr(Entries.ENTRY1), '<Entries.ENTRY1: ha hah!>')
self.assertTrue(Entries.ENTRY1.value == Foo(1), Entries.ENTRY1.value)
self.assertTrue(isinstance(Entries.ENTRY1, Foo))
self.assertTrue(Entries._member_type_ is Foo, Entries._member_type_)
self.assertTrue(Entries.ENTRY1.value == Foo(1), Entries.ENTRY1.value)
Expand All @@ -2679,7 +2677,7 @@ class Foo:
def __init__(self, a):
self.a = a
def __repr__(self):
return f'Foo(a={self.a!r})'
return 'Foo(a=%r)' % self._value_
class Entries(Foo, Enum):
ENTRY1 = 1
#
Expand Down