Skip to content

Commit 41ef39b

Browse files
committed
fix: use importlib.import_module instead of __import__
`import_module` is newer, and provides a couple of advantages over a bare `__import__`: > The import_module() function acts as a simplifying wrapper around importlib.__import__(). This means all semantics of the function are derived from importlib.__import__(). The most important difference between these two functions is that import_module() returns the specified package or module (e.g. pkg.mod), while __import__() returns the top-level package or module (e.g. pkg). It's unclear if this will actually fix any problems in the real world, but there's no recent to use `__import__` at this point AFAICT.
1 parent 1fdbb6c commit 41ef39b

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/taskgraph/util/python_path.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

5+
import importlib
56
import inspect
67
import os
78

@@ -19,9 +20,7 @@ def find_object(modulepath, objectpath):
1920
raise ValueError(f'python path {path!r} does not have the form "module:object"')
2021

2122
modulepath, objectpath = path.split(":")
22-
obj = __import__(modulepath)
23-
for a in modulepath.split(".")[1:]:
24-
obj = getattr(obj, a)
23+
obj = importlib.import_module(modulepath)
2524
for a in objectpath.split("."):
2625
obj = getattr(obj, a)
2726
return obj

0 commit comments

Comments
 (0)