diff --git a/src/taskgraph/util/python_path.py b/src/taskgraph/util/python_path.py index ff7e255e..6119e0ae 100644 --- a/src/taskgraph/util/python_path.py +++ b/src/taskgraph/util/python_path.py @@ -2,11 +2,13 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. +import importlib import inspect import os +from typing import Callable -def find_object(path): +def find_object(path: str) -> Callable: """ Find a Python object given a path of the form :. Conceptually equivalent to @@ -19,11 +21,11 @@ def find_object(modulepath, objectpath): raise ValueError(f'python path {path!r} does not have the form "module:object"') modulepath, objectpath = path.split(":") - obj = __import__(modulepath) - for a in modulepath.split(".")[1:]: - obj = getattr(obj, a) + obj = importlib.import_module(modulepath) for a in objectpath.split("."): obj = getattr(obj, a) + + assert callable(obj) return obj