cli/query: allow querying dynamic functions
This commit is contained in:
parent
dd928964e6
commit
83725e49dd
1 changed files with 9 additions and 0 deletions
|
@ -54,6 +54,15 @@ def locate_function(module_name: str, function_name: str) -> Callable[[], Iterab
|
|||
for (fname, func) in inspect.getmembers(mod, inspect.isfunction):
|
||||
if fname == function_name:
|
||||
return func
|
||||
try:
|
||||
# incase the function is defined dynamically,
|
||||
# like with a globals().setdefault(...) or a module-level __getattr__ function
|
||||
func = getattr(mod, function_name)
|
||||
if callable(func):
|
||||
return func
|
||||
except AttributeError:
|
||||
# shouldn't raise an error here, just fall through
|
||||
pass
|
||||
except Exception as e:
|
||||
raise QueryException(str(e))
|
||||
raise QueryException(f"Could not find function '{function_name}' in '{module_name}'")
|
||||
|
|
Loading…
Add table
Reference in a new issue