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
{{ message }}
Repository navigation
Cannot inherit frozen dataclass from a non-frozen one error when using pydantic frozen=True #14857
Similar to in #14850, I believe this is actually an issue with the Pydantic library's use of dataclass_transform. From looking at the code, it seems that BaseModel is itself using the transform and should be treated as a dataclass, so per the standard, frozen dataclasses cannot subclass it.
You may be able to use the same workaround as suggested in #14850 (using the latest version of the Pydantic plugin).
After double checking the spec (whoops), there is actually a provision for this:
Frozen dataclasses cannot inherit from non-frozen dataclasses. A class that has been decorated with dataclass_transform is considered neither frozen nor non-frozen, thus allowing frozen classes to inherit from it. Similarly, a class that directly specifies a metaclass that is decorated with dataclass_transform is considered neither frozen nor non-frozen.
This seems to be the only way to declare a class that has dataclass semantics but which is treated as neither frozen nor non-frozen. This is definitely a bug in MyPy; I will try to create a PR to fix it.
Activity
wesleywright commentedon Mar 10, 2023
Similar to in #14850, I believe this is actually an issue with the Pydantic library's use of
dataclass_transform. From looking at the code, it seems thatBaseModelis itself using the transform and should be treated as a dataclass, so per the standard, frozen dataclasses cannot subclass it.You may be able to use the same workaround as suggested in #14850 (using the latest version of the Pydantic plugin).
wesleywright commentedon Mar 10, 2023
After double checking the spec (whoops), there is actually a provision for this:
This seems to be the only way to declare a class that has dataclass semantics but which is treated as neither frozen nor non-frozen. This is definitely a bug in MyPy; I will try to create a PR to fix it.
[dataclass_transform] fix frozen behavior for base classes with direc…