Relative Content

Tag Archive for pythonmypypydantic

Mypy fails with Expected type ‘Type[T]’, got ‘UnionType’ instead

I’m using pydantic to load data from JSON files that can have different parameters, for this example either x or y. I use a Loader class to load them into pydantic models so that I can validate them at runtime but I cannot make my code compliant with mypy. It fails with this error: Expected type 'Type[T]', got 'UnionType' instead.