mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-42901: [Enum] move member creation to __set_name__
(GH-24196)
`type.__new__` calls `__set_name__` and `__init_subclass__`, which means that any work metaclasses do after calling `super().__new__()` will not be available to those two methods. In particular, `Enum` classes that want to make use of `__init_subclass__` will not see any members. Almost all customization is therefore moved to before the `type.__new__()` call, including changing all members to a proto member descriptor with a `__set_name__` that will do the final conversion of a member to be an instance of the `Enum` class.
This commit is contained in:
parent
c47c78b878
commit
c314e60388
4 changed files with 207 additions and 110 deletions
|
@ -408,7 +408,7 @@ def classify_class_attrs(cls):
|
|||
# attribute with the same name as a DynamicClassAttribute exists.
|
||||
for base in mro:
|
||||
for k, v in base.__dict__.items():
|
||||
if isinstance(v, types.DynamicClassAttribute):
|
||||
if isinstance(v, types.DynamicClassAttribute) and v.fget is not None:
|
||||
names.append(k)
|
||||
result = []
|
||||
processed = set()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue