class Test(Service): def get(self): return object() A = LazyMethodCall(get, singleton=True) B = LazyMethodCall(get, singleton=False) C = LazyMethodCall(get)
class Conf(Service): def fetch(self, value, service: Provide[MyService]): return value DATA = LazyMethodCall(fetch) KW = LazyMethodCall(fetch)(value='1') DATA2 = LazyMethodCall(fetch, singleton=False) KW2 = LazyMethodCall(fetch, singleton=False)(value='2')
class Service3(Service): __antidote__ = Service.Conf(singleton=False).with_wiring( dependencies=dict(i=Interface @ impl, service2=Service2 @ BuildS2)) def __init__(self, service1: Provide[Service1], service2: Service2, i: Interface): self.service1 = service1 self.service2 = service2 self.i = i def get(self, service1: Provide[Service1]): pass X = LazyMethodCall(get)
class Test(Service): def get(self): return "Hello" A = LazyMethodCall(get)
class Test(Service): def get(self, s): return s A = LazyMethodCall(get)(x)
class Dummy: def get(self, x): pass A = LazyMethodCall(get) B = LazyMethodCall(get)(x=1)
def test_invalid_lazy_method_call(): with pytest.raises(TypeError, match=".*method.*"): LazyMethodCall(method=object()) with pytest.raises(TypeError, match=".*singleton.*"): LazyMethodCall(method=lambda: None, singleton=object())
class Test(Service): def get(self, *args_, **kwargs_): return args_, kwargs_ A = LazyMethodCall(get)(*args, **kwargs)