diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-07-17 04:53:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-17 04:53:41 (GMT) |
commit | 30f28ac296e506b336e0ab56c41422a53c36d0c2 (patch) | |
tree | 80e2ebe514ff3654a5a100b0ba11faf0fb6ba4fb /Lib/enum.py | |
parent | 5a34287b5dc75293bea02489feda22b4b6b28e3e (diff) | |
download | cpython-30f28ac296e506b336e0ab56c41422a53c36d0c2.zip cpython-30f28ac296e506b336e0ab56c41422a53c36d0c2.tar.gz cpython-30f28ac296e506b336e0ab56c41422a53c36d0c2.tar.bz2 |
gh-93910: [Enum] restore member.member restriction while keeping performance boost (GH-94913)
(cherry picked from commit c20186c3972ff38577c4c5e32ca86748210983d2)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Diffstat (limited to 'Lib/enum.py')
-rw-r--r-- | Lib/enum.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/enum.py b/Lib/enum.py index e597191..b19d40c 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -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. |