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

Function instantiate

python/core/ltp_core/models/utils/instantiate.py:27–46  ·  view source on GitHub ↗
(config, target="_ltp_target_", partial="_ltp_partial_")

Source from the content-addressed store, hash-verified

25
26
27def instantiate(config, target="_ltp_target_", partial="_ltp_partial_"):
28 if isinstance(config, dict) and target in config:
29 target_path = config.get(target)
30 target_callable = find_callable(target_path)
31
32 is_partial = config.get(partial, False)
33 target_args = {
34 key: instantiate(value)
35 for key, value in config.items()
36 if key not in [target, partial]
37 }
38
39 if is_partial:
40 return functools.partial(target_callable, **target_args)
41 else:
42 return target_callable(**target_args)
43 elif isinstance(config, dict):
44 return {key: instantiate(value) for key, value in config.items()}
45 else:
46 return config
47
48
49def instantiate_omega(config, target="_ltp_target_", partial="_ltp_partial_"):

Callers 3

__init__Method · 0.90
__init__Method · 0.90
mainFunction · 0.85

Calls 1

find_callableFunction · 0.85

Tested by

no test coverage detected