Closed ja-albert closed 1 year ago
Hi @ja-albert.
Thanks for your report.
Yes, the problem is here.
mypy can't figure out that type(BaseModel)
returns ModelMetaclass
and thinks that BaseModel
and BaseXmlModel
have different metaclass roots which is prohibited in python.
The other problem is that ModelMetaclass
located in an internal pydantic module which means it is not a public api and can be changed in the future.
Found the issue addressing that problem. They advice to import ModelMetaclass
directly from pydantic._internal._model_construction
.
I will fix it in the next release.
Thank you, the problem is fixed in the new release :+1:
Hi :) Again, thank you for your work and your quick fix in my previous issue!
I found a new problem in
v2.0.0b1
, which I could not reproduce inv1.0.0
. MWE:Running
mypy
on it results in:I'm unsure if this is a
mypy
bug or not, but in my normal code, this results in thismypy
error for each subclass ofBaseXmlModel
I have.I also found this
mypy
issue which suggests that adding a# type: ignore[misc]
to theclass BaseXmlModel
line could be a workaround: https://github.com/python/mypy/issues/14033#issuecomment-1307044115 But to be honest, I do not know enough about Python metaclasses to give you a better problem analysis and solution proposal. On the other hand, you may already have seen a similar issue, as you apparently added the same type ignore a few lines above theBaseXmlModel
definition for version 2: https://github.com/dapper91/pydantic-xml/blob/v2.0.0b1/pydantic_xml/model.py#L202