Jun-17-2020, 11:39 AM
(This post was last modified: Jun-17-2020, 06:54 PM by gontajones.)
Hey guys, I'm having hard time to make a clean type hint of an SQLAlchemy project that I'm working on.
The issue is that I need type hint for some methods that accept only a bunch of models from a file (eg
Something like this:
Is it possible to get all classes from a file and insert them into the
That way it would be more clean and even much more maintainable. Like:
The issue is that I need type hint for some methods that accept only a bunch of models from a file (eg
models.py)Something like this:
from typing import Union
from models import M1, M2, ..., M20
def func(table: Union[M1, M2, ..., M20]) -> bool
...
return TrueSo this is getting too big and ugly
Is it possible to get all classes from a file and insert them into the
Union?That way it would be more clean and even much more maintainable. Like:
from typing import Union
import models as m
def func(table: Union[model for model in dir(m)]) -> bool
...
return TrueThis won't work as it is but is just the idea
