Skip to content

mypy: Metaclass conflict in v2 #89

Closed
@ja-albert

Description

@ja-albert

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 in v1.0.0. MWE:

from pydantic_xml import BaseXmlModel

class A(BaseXmlModel): pass

Running mypy on it results in:

$ mypy test.py
test.py:3: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]

I'm unsure if this is a mypy bug or not, but in my normal code, this results in this mypy error for each subclass of BaseXmlModel I have.

I also found this mypy issue which suggests that adding a # type: ignore[misc] to the class BaseXmlModel line could be a workaround: python/mypy#14033 (comment)
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 the BaseXmlModel definition for version 2: https://github.com/dapper91/pydantic-xml/blob/v2.0.0b1/pydantic_xml/model.py#L202

Metadata

Metadata

Assignees

No one assigned

    Labels

    typingRelated to typingv2Version 2 related

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions