Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TypeError when raising an exception inside the__init__ method of an enum class #125259

Closed
Labels
3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@Viicos

Description

@Viicos

Bug report

Bug description:

With#111815, any exception raised inside the__init__ method of an enum class1 is expected to be:

  1. instantiable (not the case with PydanticValidationErrors, seePython 3.12 Enum Class Validated Initialization TypeError pydantic/pydantic#10593)
  2. instantiable and expected to take a single argument.

cpython/Lib/enum.py

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

Footnotes

  1. An example is documented as an examplehere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp