Return an attribute from a dotted path name (e.g. "path.to.func").
(name: str)
| 61 | |
| 62 | # from rq |
| 63 | def import_attribute(name: str) -> Any: |
| 64 | """Return an attribute from a dotted path name (e.g. "path.to.func").""" |
| 65 | try: |
| 66 | sep = ":" if ":" in name else "." # For backwards compatibility |
| 67 | module_name, attribute = name.rsplit(sep, 1) |
| 68 | module = importlib.import_module(module_name) |
| 69 | return operator.attrgetter(attribute)(module) |
| 70 | except (ValueError, ImportError, AttributeError) as e: |
| 71 | raise TaskImportError(e) |
| 72 | |
| 73 | |
| 74 | def gen_id() -> str: |
no test coverage detected