Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Closed
Description
Bug report
Bug description:
With#111815, any exception raised inside the__init__ method of an enum class1 is expected to be:
- instantiable (not the case with Pydantic
ValidationErrors, seePython 3.12 Enum Class Validated Initialization TypeError pydantic/pydantic#10593) - instantiable and expected to take a single argument.
Lines 556 to 566 in120b891
| try: | |
| exc=None | |
| classdict['_%s__in_progress'%cls]=True | |
| enum_class=super().__new__(metacls,cls,bases,classdict,**kwds) | |
| classdict['_%s__in_progress'%cls]=False | |
| delattr(enum_class,'_%s__in_progress'%cls) | |
| exceptExceptionase: | |
| # since 3.12 the line "Error calling __set_name__ on '_proto_member' instance ..." | |
| # is tacked on to the error instead of raising a RuntimeError | |
| # recreate the exception to discard | |
| exc=type(e)(str(e)) |
Meaning the following raises aTypeError instead of the expectedMyValueError:
classMyValueError(ValueError):def__init__(self,t:str,v:int)->None:self.t=tself.v=vclassValidatedEnum(Enum):def__init__(self,value):raiseMyValueError("",1)classMyValidatedEnum(ValidatedEnum):FOO="foo"# TypeError: MyValueError.__init__() missing 1 required positional argument: 'v'
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
- gh-125259: Fix error notes removal in enum initialization #125647
- [3.13] gh-125259: Fix error notes removal in enum initialization (GH-125647) #125858
- [3.12] gh-125259: Fix error notes removal in enum initialization (GH-125647) #125953