Commit a08d8f44 authored by Wout De Nolf's avatar Wout De Nolf
Browse files

esrftaskgraph: proper qualname for builtins

parent b12489b5
import importlib import importlib
def qualname(_type): def qualname(obj):
mod_name = _type.__module__ return obj.__module__ + "." + obj.__name__
if not mod_name or mod_name == str.__module__:
return _type.__name__ # Avoid reporting builtins
else:
return mod_name + "." + _type.__name__
def import_qualname(qualname): def import_qualname(qualname):
if not isinstance(qualname, str): if not isinstance(qualname, str):
raise TypeError(qualname, type(qualname)) raise TypeError(qualname, type(qualname))
module_name, dot, name = qualname.rpartition(".") module_name, dot, obj_name = qualname.rpartition(".")
if not module_name: if not module_name:
raise ImportError(f"cannot import {qualname}") raise ImportError(f"cannot import {qualname}")
module = importlib.import_module(module_name) module = importlib.import_module(module_name)
try: try:
return getattr(module, name) return getattr(module, obj_name)
except AttributeError: except AttributeError:
raise ImportError(f"cannot import {name} from {module_name}") raise ImportError(f"cannot import {obj_name} from {module_name}")
def import_method(qualname): def import_method(qualname):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment