mypy “is not valid as a type” for types constructed with `type()`
How about this, as a workaround? from typing import Optional, TYPE_CHECKING if TYPE_CHECKING: class Foo: pass else: Foo = type(‘Foo’, (), {}) Bar = Optional[Foo] typing.TYPE_CHECKING is a constant that will always be True at compile-time, and will always be False at runtime. In this way, we can keep MyPy happy by only telling it … Read more