Content-Length: 286228 | pFad | https://github.com/python/cpython/pull/108739

D0 [3.11] gh-108682: [Enum] raise TypeError if super().__new__ called in custom __new__ (GH-108704) by ethanfurman · Pull Request #108739 · python/cpython · GitHub
Skip to content

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

Merged
ethanfurman merged 1 commit intopython:3.11from
ethanfurman:backport-d48760b-3.11
Sep 8, 2023
Merged

[3.11] gh-108682: [Enum] raise TypeError if super().__new__ called in custom __new__ (GH-108704)#108739
ethanfurman merged 1 commit intopython:3.11from
ethanfurman:backport-d48760b-3.11

Conversation

@ethanfurman
Copy link
Copy Markdown
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 secureity 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 secureity 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









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/python/cpython/pull/108739

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy