mypy complains error: Variable "packagename.Foo" is not valid as a type
Foo = type('Foo', (), {})
Bar = Optional[Foo]
This error can be fixed by defining the type as a class:
class Foo:
pass
Bar = Optional[Foo]
Is there any other way around this? I need to keep the type definition dynamic.