-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
The last line of the following code results in the runtime TypeError:
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
import typing
import typing_extensions
class Foo(typing.TypedDict): ...
class Bar(typing_extensions.TypedDict): ...
class Baz(Foo, Bar): ...I just ran into this runtime error because I always default to using types from typing but sometimes use types from typing_extensions to support older versions of Python. In particular typing.TypedDict is incompatible with typing.Generic in Python < 3.11, see python/cpython#27663 (comment), so I sometimes used typing_extensions.TypedDict instead of typing.TypedDict.
It would be nice if pyright could detect this type error, which can be quite sneaky.
I think there could even be an additional optional check that warns about this issue whenever a project uses both typing.TypedDict and typing_extensions.TypedDict in the same code base (because otherwise the public API might have TypedDict classes that are incompatible with each other).