mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-01-18 12:06:08 +00:00
utils/misc: Replace deprecated __import__ by importlib
Use importlib.import_module instead of __import__ as per Python doc recommendation. This will also fix the case where the class is in a package's submodule (since __import__ returns the top-level package), e.g. "foo.bar.Class".
This commit is contained in:
parent
77ebefba08
commit
28b78a93f1
@ -236,7 +236,12 @@ def load_class(classpath):
|
|||||||
"""Loads the specified Python class. ``classpath`` must be a fully-qualified
|
"""Loads the specified Python class. ``classpath`` must be a fully-qualified
|
||||||
class name (i.e. namspaced under module/package)."""
|
class name (i.e. namspaced under module/package)."""
|
||||||
modname, clsname = classpath.rsplit('.', 1)
|
modname, clsname = classpath.rsplit('.', 1)
|
||||||
return getattr(__import__(modname), clsname)
|
mod = importlib.import_module(modname)
|
||||||
|
cls = getattr(mod, clsname)
|
||||||
|
if isinstance(cls, type):
|
||||||
|
return cls
|
||||||
|
else:
|
||||||
|
raise ValueError(f'The classpath "{classpath}" does not point at a class: {cls}')
|
||||||
|
|
||||||
|
|
||||||
def get_pager():
|
def get_pager():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user