Skip to content

[3.12] gh-108682: [Enum] raise TypeError if super().__new__ called in custom __new__ (GH-108704) #108733

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

Merged
merged 1 commit into from
Aug 31, 2023

Conversation

miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Aug 31, 2023

When overriding the __new__ method of an enum, the underlying data type should be created directly; i.e. .

member = object.__new__(cls)
member = int.__new__(cls, value)
member = str.__new__(cls, value)

Calling super().__new__() finds the lookup version of Enum.__new__, and will now raise an exception when detected.
(cherry picked from commit d48760b)

Co-authored-by: Ethan Furman ethan@stoneleaf.us


📚 Documentation preview 📚: https://cpython-previews--108733.org.readthedocs.build/

…custom __new__ (pythonGH-108704)

When overriding the `__new__` method of an enum, the underlying data type should be created directly; i.e. .

    member = object.__new__(cls)
    member = int.__new__(cls, value)
    member = str.__new__(cls, value)

Calling `super().__new__()` finds the lookup version of `Enum.__new__`, and will now raise an exception when detected.
(cherry picked from commit d48760b)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
@ethanfurman ethanfurman requested a review from Yhg1s August 31, 2023 19:54
@Yhg1s Yhg1s merged commit 8c3793a into python:3.12 Aug 31, 2023
@miss-islington miss-islington deleted the backport-d48760b-3.12 branch August 31, 2023 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants