]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.12] gh-108682: [Enum] raise TypeError if super().__new__ called in custom __new__...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 31 Aug 2023 22:04:55 +0000 (15:04 -0700)
committerGitHub <noreply@github.com>
Thu, 31 Aug 2023 22:04:55 +0000 (00:04 +0200)
commit8c3793a539ce950e552da390b7b24485dd655237
treef270c1cc50d17f694166ac1b6af27c2c3006091d
parenta92c60c99bab716d1d08bccb92dcc0fe6ee93abe
[3.12] gh-108682: [Enum] raise TypeError if super().__new__ called in custom __new__ (GH-108704) (#108733)

gh-108682: [Enum] raise TypeError if super().__new__ called in custom __new__ (GH-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 d48760b2f1e28dd3c1a35721939f400a8ab619b8)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Doc/howto/enum.rst
Lib/enum.py
Lib/test/test_enum.py
Misc/NEWS.d/next/Library/2023-08-30-20-10-28.gh-issue-108682.c2gzLQ.rst [new file with mode: 0644]