mirror of
https://github.com/python/cpython.git
synced 2025-10-07 15:42:02 +00:00
gh-93910: [Enum] restore member.member restriction while keeping performance boost (GH-94913)
(cherry picked from commit c20186c397
)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
This commit is contained in:
parent
5a34287b5d
commit
30f28ac296
2 changed files with 14 additions and 1 deletions
|
@ -1114,6 +1114,14 @@ class Enum(metaclass=EnumType):
|
|||
def __init__(self, *args, **kwds):
|
||||
pass
|
||||
|
||||
def __getattribute__(self, name):
|
||||
self_dict = super().__getattribute__('__dict__')
|
||||
cls = super().__getattribute__('__class__')
|
||||
value = super().__getattribute__(name)
|
||||
if isinstance(value, cls) and name not in self_dict and name in self._member_names_:
|
||||
raise AttributeError("<enum '%s'> member has no attribute %r" % (cls.__name__, name))
|
||||
return super().__getattribute__(name)
|
||||
|
||||
def _generate_next_value_(name, start, count, last_values):
|
||||
"""
|
||||
Generate the next value when not given.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue