codekingpro/portable-devtools
114k
1import importlib
2from typing import Type, TypeVar, cast
3
4C = TypeVar("C")
5
6
7def get_class(fqn: str, type: Type[C]) -> Type[C]:
8 """Given a fully qualifed class name, import the module and return the class"""
9 module_name, class_name = fqn.rsplit(".", 1)
10 module = importlib.import_module(module_name)
11 cls = getattr(module, class_name)
12 return cast(Type[C], cls)
13 