Skip to content

Commit

Permalink
feat: return self if calling dependency without args (supports future…
Browse files Browse the repository at this point in the history
… Dependency.grab() syntax).
  • Loading branch information
joshorr committed Nov 2, 2022
1 parent 71fee52 commit c2ebe5b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion udepend/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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. "
Expand Down

0 comments on commit c2ebe5b

Please sign in to comment.