MCPcopy
hub / github.com/HIT-SCIR/ltp / find_callable

Function find_callable

python/core/ltp_core/models/utils/instantiate.py:6–24  ·  view source on GitHub ↗
(target: str)

Source from the content-addressed store, hash-verified

4
5
6def find_callable(target: str) -> Callable:
7 target_module_path, target_callable_path = target.rsplit(".", 1)
8 target_callable_paths = [target_callable_path]
9
10 target_module = None
11 while len(target_module_path):
12 try:
13 target_module = importlib.import_module(target_module_path)
14 break
15 except Exception as e:
16 target_module_path, target_callable_path = target_module_path.rsplit(".", 1)
17 if len(target_module_path) == 0:
18 raise e
19 target_callable_paths.append(target_callable_path)
20 target_callable = target_module
21 for attr in reversed(target_callable_paths):
22 target_callable = getattr(target_callable, attr)
23
24 return target_callable
25
26
27def instantiate(config, target="_ltp_target_", partial="_ltp_partial_"):

Callers 2

instantiateFunction · 0.85
instantiate_omegaFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected