| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Calling an enum class (Color(1)) performs a member lookup by value via EnumMeta.__call__. A user-defined __init__ or __new__ only runs when the members are created, so it should not affect the signature of the call. Previously mypy built the signature from the user's constructor and reported a [call-arg] error
|
Diff from mypy_primer, showing the effect of this PR on open source code: scipy-stubs (https://github.com/scipy/scipy-stubs)
- tests/misc/test_submodules_empty.pyi:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
|
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes part of #16806 (the type-checker problem reported in the comment NOT the stubtest part).
The bug
Calling an enum class looks up a member by value at runtime, through EnumMeta.__call__.
A user-defined __init__ or __new__ only runs while the members are being created. mypy didn't account for this and used the user's constructor signature for the call, so this valid code was rejected:
The proposed fix
The fix adds a small helper, enum_call_constructor, in mypy/typeops.py.
When an enum defines its own __init__ or __new__, type_object_type uses Enum.__new__(cls, value) for the call signature. Otherwise the existing logic runs unchanged.