Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-42901: [Enum] move member creation to __set_name__ #24196

Merged
merged 1 commit into from Jan 13, 2021

Conversation

ethanfurman
Copy link
Member

@ethanfurman ethanfurman commented Jan 12, 2021

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.

https://bugs.python.org/issue42901

`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.
@ethanfurman ethanfurman self-assigned this Jan 12, 2021
@ethanfurman ethanfurman merged commit c314e60 into python:master Jan 13, 2021
11 checks passed
@ethanfurman ethanfurman deleted the enum-member_by_set_name branch Jan 14, 2021
m000 pushed a commit to m000/cpython that referenced this issue Jan 29, 2021
)

`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.
adorilson pushed a commit to adorilson/cpython that referenced this issue Mar 13, 2021
)

`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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants