Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions invoke/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,19 @@ def argspec(self, body):
# TODO: __call__ exhibits the 'self' arg; do we manually nix 1st result
# in argspec, or is there a way to get the "really callable" spec?
func = body if isinstance(body, types.FunctionType) else body.__call__
spec = inspect.getargspec(func)
arg_names = spec.args[:]
matched_args = [reversed(x) for x in [spec.args, spec.defaults or []]]
spec_dict = dict(zip_longest(*matched_args, fillvalue=NO_DEFAULT))
if six.PY3:
sig = inspect.signature(func)
arg_names = [k for k, v in sig.parameters.items()]
spec_dict = {}
for k, v in sig.parameters.items():
value = v.default if not v.default == sig.empty else NO_DEFAULT
spec_dict.update({k: value})
else:
spec = inspect.getargspec(func)
arg_names = spec.args[:]
matched_args = [
reversed(x) for x in [spec.args, spec.defaults or []]]
spec_dict = dict(zip_longest(*matched_args, fillvalue=NO_DEFAULT))
# Pop context argument
try:
context_arg = arg_names.pop(0)
Expand Down
2 changes: 1 addition & 1 deletion tests/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def prefers_task_name_attr_over_function_name(self):
def raises_ValueError_if_no_name_found(self):
# Can't use a lambda here as they are technically real functions.
class Callable(object):
def __call__(self):
def __call__(self, ctx):
pass
self.c.add_task(Task(Callable()))

Expand Down