-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
Closed as not planned
Closed as not planned
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
It seems the pull request (#108704) that tried to handle erroneous calls to Enum.__new__ introduced some other behavior as well. In a few projects that I'm involved with we use this pattern:
from enum import Enum
class Result(Enum):
@classmethod
def _missing_(cls, value):
v = None
for subclass in cls.__subclasses__():
try:
v = subclass(value)
except:
pass
return v
class CommonResult(Result):
OK = 0
ERR_FOO = -0x1
ERR_BAR = -0x2where calling Result(0) would return CommonResult.OK. Now in 3.11.6 and onwards this throws a TypeError. Was this intentional? It's a nice pattern to have and there are to me no obvious ways to replace it with something as elegant, so I hope that it can be solved some other way (maybe by checking if the class actually overrides __new__ and if not, then allowing the call to _missing_?)
CPython versions tested on:
3.11, 3.12
Operating systems tested on:
Linux, Windows
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error