-
Mypy complains at ClassB about: "Definition of "Config" in base class "Model" is incompatible with definition in base class "BaseClass"" What is the problem here?
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
This is accepted by mypy, note that Model is now a subclass of BaseModel.
My goals is to use ClassA like a value object (immutable, no business logic) and ClassB like a business model object (mutable, can contain business logic). I would like to inherit fields between the two types, therefore the inheritance of ClassA by ClassB. I would also like to change the pydantic config for ClassB to be mutable. That is why I want to set allow_mutation=False on ClassA and allow_mutation=True on ClassB. |
Beta Was this translation helpful? Give feedback.
-
Mypy is correct, the two config classes are incompatible with each other, in the same way that you cannot assign an object of class class A: ...
class B: ...
class Model:
a: A
class Submodel(Model):
a: B # Invalid The confusion arises here from the classes being synonymous. |
Beta Was this translation helpful? Give feedback.
Mypy is correct, the two config classes are incompatible with each other, in the same way that you cannot assign an object of class
A
to a variable declared to be aB
if one does not inherit from the other:The confusion arises here from the classes being synonymous.