Reputation: 3201
I have a module foo
that defines a lot of classes, e.g.
class A():
...
class B():
...
class C():
...
...
I would like to create a "foo type" alias comprising all these classes, i.e.
my_foo_type = Union[A, B, C, ...]
Yet, there are so many classes that I don't want to type them but have programmatic solution. I access to all classes defined in the module via
for name, obj in inspect.getmembers(foo):
if inspect.isclass(obj):
print(obj)
How can I connect this with the type alias?
Upvotes: 3
Views: 531
Reputation: 46843
I don't think it's possible. I don't know what you want to do with your classes but depending on your use case, you could:
Upvotes: 1