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
With the new dataclass transform decorator, Pyright reports for frozen models that they are not hashable:
# pyright: strictfromtypingimportHashablefrompydanticimportBaseModelclassFoo(BaseModel, frozen=True):
passfoo: Hashable=Foo() # Error: Expression of type "Foo" cannot be assigned to declared type "Hashable"reveal_type(Foo.__hash__) # Type of "Foo.__hash__" is "None"fromdataclassesimportdataclass@dataclass(frozen=True)classBar:
passbar: Hashable=Bar() # No errorreveal_type(Bar.__hash__) # Type of "Bar.__hash__" is "(self: Bar) -> int"
Peculiarly if I change eq_default to false on the ModelMetaclass then it type checks but I don't see why that should be.
Okay, yeah, it just straight up doesn't seem to pick up frozen. Because, for dataclasses, "... If eq is true and frozen is false, __hash__() will be set to None" (which is how hashing behaves in Python more generally - implementing __eq__ automatically sets __hash__ to None).
With the new dataclass transform decorator, Pyright reports for
frozen
models that they are not hashable:Originally posted by @layday in #2721 (comment)
The text was updated successfully, but these errors were encountered: