Skip to content

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