Bug Report
When an Enum is created that takes multiple initialisation arguments then the signature for calling the Enum with the value is incorrectly inferred to expect every parameter from __new__ and/or __init__ rather than just the value type.
To Reproduce
from enum import IntEnum
from typing import Final, Type
class Colour(IntEnum):
value: int
r: Final[int]
g: Final[int]
b: Final[int]
RED = 0, b"\xFF\x00\x00"
GREEN = 1, b"\x00\xFF\x00"
BLUE = 2, b"\x00\x00\xFF"
def __new__(cls: Type["Colour"], value: int, _hue: bytes) -> "Colour":
member = int.__new__(cls, value)
member._value_ = value
return member
def __init__(self: "Colour", _value: int, hue: bytes) -> None:
self.r = hue[0]
self.g = hue[1]
self.b = hue[2]
c = Colour(0)
print(c)
Expected Behavior
MyPy should have no errors.
Actual Behavior
Outputs:
test_call_enum.py:24: error: Missing positional argument "hue" in call to "Colour"
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 0.812
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini (and other config files): None
- Python version used: 3.8.10
- Operating system and version: Ubuntu 18.04
Bug Report
When an
Enumis created that takes multiple initialisation arguments then the signature for calling theEnumwith the value is incorrectly inferred to expect every parameter from__new__and/or__init__rather than just thevaluetype.To Reproduce
Expected Behavior
MyPy should have no errors.
Actual Behavior
Outputs:
Your Environment
mypy.ini(and other config files): None