Andrew Svetlov <[email protected]> added the comment:
Thank you very much for raising the question.
@patch(...) creates _patch class instance.
For decoration _patch.__call__ is used.
def __call__(self, func):
if isinstance(func, type):
return self.decorate_class(func)
return self.decorate_callable(func)
The code can be modified to
def __call__(self, func):
if isinstance(func, type):
return self.decorate_class(func)
if inspect.iscoroutinefunction(func):
return self.decorate_async_func(func)
return self.decorate_callable(func)
decorate_async_func can do all the same as decorate_callable with the only
difference: internal
@wraps(func)
def patched(*args, **keywargs):
should be replaced with
@wraps(func)
async def patched(*args, **keywargs):
and
return func(*args, **keywargs)
replaced with
return await func(*args, **keywargs)
Pretty straightforward.
I did not check the code though.
I'm pretty busy up to 3.8 feature freeze to make the PR for proposed change but
I love to review the existing patch.
Do want somebody to be a champion?
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36996>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com