Skip to content

Conversation

ethanfurman
Copy link
Member

@ethanfurman ethanfurman 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)


📚 Documentation preview 📚: https://cpython-previews--108739.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)
@ethanfurman ethanfurman added type-bug An unexpected behavior, bug, or error stdlib Standard Library Python modules in the Lib/ directory 3.11 only security fixes labels Aug 31, 2023
@ethanfurman ethanfurman self-assigned this Aug 31, 2023
@ethanfurman ethanfurman merged commit effa2ec into python:3.11 Sep 8, 2023
@ethanfurman ethanfurman deleted the backport-d48760b-3.11 branch September 8, 2023 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes stdlib Standard Library Python modules in the Lib/ directory type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants