summaryrefslogtreecommitdiffstats
path: root/Lib/enum.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/enum.py')
-rw-r--r--Lib/enum.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index d744f8f..5be13d5 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -112,6 +112,10 @@ class EnumMeta(type):
enum_class._member_map_ = OrderedDict() # name->value map
enum_class._member_type_ = member_type
+ # save attributes from super classes so we know if we can take
+ # the shortcut of storing members in the class dict
+ base_attributes = {a for b in bases for a in b.__dict__}
+
# Reverse value->name map for hashable values.
enum_class._value2member_map_ = {}
@@ -165,6 +169,11 @@ class EnumMeta(type):
else:
# Aliases don't appear in member names (only in __members__).
enum_class._member_names_.append(member_name)
+ # performance boost for any member that would not shadow
+ # a DynamicClassAttribute
+ if member_name not in base_attributes:
+ setattr(enum_class, member_name, enum_member)
+ # now add to _member_map_
enum_class._member_map_[member_name] = enum_member
try:
# This may fail if value is not hashable. We can't add the value
@@ -468,7 +477,7 @@ class Enum(metaclass=EnumMeta):
m
for cls in self.__class__.mro()
for m in cls.__dict__
- if m[0] != '_'
+ if m[0] != '_' and m not in self._member_map_
]
return (['__class__', '__doc__', '__module__'] + added_behavior)