Skip to content

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

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
Sep 8, 2023

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 Python modules in the Lib dir 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 Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants