Commit 08bc843e authored by jpic ∞'s avatar jpic ∞ 💾
Browse files

Support async callbacks

parent b4216bf5
from asgiref import sync
import collections
import inspect
import importlib
......@@ -189,8 +190,14 @@ class Callable(Importable):
req_args = self.required_args
if len(args) < len(req_args):
raise Cli2ArgsException(self, args)
if inspect.iscoroutinefunction(self.target):
target = sync.async_to_sync(self.target)
else:
target = self.target
try:
return self.target(*args, **kwargs)
return target(*args, **kwargs)
except TypeError as exc:
# catch builtins that don't provide info for required_args
if exc.args[0].startswith('Required argument'):
......
......@@ -5,7 +5,7 @@ setup(
name='cli2',
versioning='dev',
setup_requires='setupmeta',
install_requires=['colorama'],
install_requires=['colorama', 'asgiref'],
extras_require=dict(
test=[
'freezegun',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment