You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to define an enum of an @attrs.define class, Mypy gives typing errors, but it works in runtime.
When trying to define an enum of an @attrs.frozen class, Mypy doesn't give an error, but it errors at runtime.
When trying to define an enum of a @dataclasses.dataclass class, Mypy doesn't give an error, and it works at runtime.
I started noticing this today after I removed support for Python 3.9 from my project, and ran poetry update.
fromdataclassesimportdataclassfromenumimportEnumimportattrsfrompytestimportraises@attrs.defineclassAttrsDefine:
a: intb: float# error: Definition of "__hash__" in base class "AttrsDefine" is incompatible with definition in base class "Enum" [misc]classAttrsDefineEnum(AttrsDefine, Enum):
X= (1, 2.0)
Y= (3, 4.0)
@attrs.frozenclassAttrsFrozen:
a: intb: float@dataclassclassDataclass:
a: intb: floatclassDataclassEnum(Dataclass, Enum):
X= (1, 2.0)
Y= (3, 4.0)
deftest_enums() ->None:
withraises(attrs.exceptions.FrozenInstanceError) asexc_info:
# attr.exceptions.FrozenInstanceErrorclassAttrsFrozenEnum(AttrsFrozen, Enum):
X= (1, 2.0)
Y= (3, 4.0)
print(repr(AttrsFrozenEnum.X))
print(exc_info.exconly())
print(repr(AttrsDefineEnum.X))
print(repr(DataclassEnum.X))
❯ mypy attrenum.py
attrenum.py:15: error: Definition of "__hash__"in base class "AttrsDefine" is incompatible with definition in base class "Enum" [misc]
Found 1 error in 1 file (checked 1 source file)
❯ pytest -s attrenum.py
=================================================================================== test session starts ===================================================================================
platform linux -- Python 3.11.6, pytest-7.4.0, pluggy-1.2.0
rootdir: /home/micael/projects/playground
collected 1 item
attrenum.py attr.exceptions.FrozenInstanceError
AttrsDefineEnum(a=1, b=2.0)
<DataclassEnum.X: Dataclass(a=1, b=2.0)>.
==================================================================================== 1 passed in 0.01s ====================================================================================
When trying to define an enum of an
@attrs.define
class, Mypy gives typing errors, but it works in runtime.When trying to define an enum of an
@attrs.frozen
class, Mypy doesn't give an error, but it errors at runtime.When trying to define an enum of a
@dataclasses.dataclass
class, Mypy doesn't give an error, and it works at runtime.I started noticing this today after I removed support for Python 3.9 from my project, and ran
poetry update
.The text was updated successfully, but these errors were encountered: