mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
bpo-46242: [Enum] better error message for extending Enum
with members (GH-30357)
This commit is contained in:
parent
2402f1e1f8
commit
e674e48ddc
3 changed files with 7 additions and 5 deletions
|
@ -763,7 +763,7 @@ class EnumType(type):
|
|||
"""
|
||||
metacls = cls.__class__
|
||||
bases = (cls, ) if type is None else (type, cls)
|
||||
_, first_enum = cls._get_mixins_(cls, bases)
|
||||
_, first_enum = cls._get_mixins_(class_name, bases)
|
||||
classdict = metacls.__prepare__(class_name, bases)
|
||||
|
||||
# special processing needed for names?
|
||||
|
@ -848,8 +848,8 @@ class EnumType(type):
|
|||
% (class_name, base.__name__)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _get_mixins_(class_name, bases):
|
||||
@classmethod
|
||||
def _get_mixins_(cls, class_name, bases):
|
||||
"""
|
||||
Returns the type for creating enum members, and the first inherited
|
||||
enum class.
|
||||
|
@ -890,9 +890,8 @@ class EnumType(type):
|
|||
if not issubclass(first_enum, Enum):
|
||||
raise TypeError("new enumerations should be created as "
|
||||
"`EnumName([mixin_type, ...] [data_type,] enum_type)`")
|
||||
cls._check_for_existing_members(class_name, bases)
|
||||
member_type = _find_data_type(bases) or object
|
||||
if first_enum._member_names_:
|
||||
raise TypeError("Cannot extend enumerations")
|
||||
return member_type, first_enum
|
||||
|
||||
@staticmethod
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue