From c2ebe5b2f801c59592afd15c229eac5f85c1b70d Mon Sep 17 00:00:00 2001 From: Josh Orr Date: Wed, 2 Nov 2022 16:10:27 -0600 Subject: [PATCH] feat: return self if calling dependency without args (supports future Dependency.grab() syntax). --- udepend/dependency.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/udepend/dependency.py b/udepend/dependency.py index 2847d6b..81b9af4 100644 --- a/udepend/dependency.py +++ b/udepend/dependency.py @@ -493,7 +493,7 @@ def __exit__(self, *args, **kwargs): context = stack.pop() context.__exit__(*args, **kwargs) - def __call__(self, func): + def __call__(self, func = None): """ This makes Resource subclasses have an ability to be used as function decorators by default unless this method is overriden to provide some other funcionality. @@ -543,6 +543,13 @@ def __call__(self, func): Returns: We execute decorated method and return whatever it returns. """ + # If we are called without any arguments, return self to support using this either as: + # `DependencySubclass.depend()` + # OR + # `DependencySubclass.depend` + if not func: + return self + if not callable(func): raise XynResourceError( f"Attempt to calling a Dependency of type ({self}) as a callable function. "