in flowtorch/lazy.py [0:0]
def __call__(cls: Any, *args: Any, **kwargs: Any) -> Any:
"""
Intercept instance creation
"""
# Special behaviour for Lazy class
if cls.__qualname__ == "Lazy":
lazy_cls = args[0]
args = args[1:]
else:
lazy_cls = cls
# Remove first argument (i.e., self) from signature of class' initializer
sig = inspect.signature(lazy_cls.__init__)
new_parameters = OrderedDict(
[(k, v) for idx, (k, v) in enumerate(sig.parameters.items()) if idx != 0]
)
sig = sig.replace(parameters=list(new_parameters.values()))
# Attempt binding arguments to initializer
bound_sig, bindings = partial_signature(sig, *args, **kwargs)
# If there are no unbound arguments then instantiate class
if not count_unbound(bound_sig):
return type.__call__(lazy_cls, *args, **kwargs)
# Otherwise, return Lazy instance
else:
return type.__call__(Lazy, lazy_cls, bindings, sig, bound_sig)