Open khalo-sa opened 1 year ago
CustomType is (since version 3.9 at least) actually an instance of type GenericAlias
. Despite it being the first argument (which is meant to work properly), calling issubclass with anything based on ABCMeta (which BaseModel and GenericModel are) results in a call to _abc_subclasscheck with the subclass last (which must not be a generic).
The pydantic maintainers encountered this early 2021 and fixed it in their pydantic.utils.lenient_issubclass
function pydantic/pydantic#2399. Swapping out the two calls to issubclass in is_concrete_pydantic_model
to that utility function solves it.
I modified the function to
def is_concrete_pydantic_model(obj) -> bool:
"""
Return true if an object is a concrete subclass of pydantic's BaseModel.
'concrete' meaning that it's not a GenericModel.
"""
return isinstance(obj, ModelMetaclass)
and I can generate typescript.
Hi and thank you for this package!
I would like to report a bug with version 1.0.10 and Python version 3.10.
Assume we have this Python file:
Now if I run
pydantic2ts --module test.py --output ./test.ts
I get the following error:Note that
CustomType
is not even used in the PydanticModel. Still, if I comment out the definition of CustomType, the error disappears.