Open simontaurus opened 1 month ago
I made a typo - actually this use case works
from pydantic import BaseModel
class Entity(BaseModel):
pass
class Item(Entity):
pass
class Person(Item):
pass
class ParamA(BaseModel):
p: BaseModel
class ParamB(BaseModel):
p: Entity
print(type(ParamA(p=Person()).p).__name__) # => Person
print(type(ParamB(p=Person()).p).__name__) # => Person
If a common base class (here
Entity
) is used for typing, casting to this class occurs when annotating a (param) class accordingly. This is not the case when usingBaseModel
for annotation.see also: https://github.com/OpenSemanticLab/osw-python/commit/1a4c7f27a27adfee29e4144d362ea01a73cec040