Skip to content

Commit 3863795

Browse files
committed
Add noargs_command decorator to __call__ magic method
1 parent 9d4cc1e commit 3863795

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

call-to-non-callable.py

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
66
pytest call-to-non-callable.py
77
"""
8+
import functools
9+
10+
11+
def noargs_command(func):
12+
@functools.wraps(func)
13+
def wrapper(self, cmd, *args, **kwargs):
14+
if len(args):
15+
cmd.logger.critical('Command does not take any arguments.')
16+
return
17+
return func(self, cmd, *args, **kwargs)
18+
return wrapper
819

920

1021
class Command(object):
@@ -13,6 +24,8 @@ def __call__(self, cmd, *args, **kwargs):
1324

1425

1526
class FooBarCommand(Command):
27+
28+
@noargs_command
1629
def __call__(self, cmd, *args, **kwargs):
1730
return f"{cmd}: foobar"
1831

0 commit comments

Comments
 (0)