This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author asvetlov
Recipients asvetlov, cjw296, lisroach, michael.foord, xtreak, yselivanov
Date 2019-05-21.19:06:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1558465591.83.0.459020555027.issue36996@roundup.psfhosted.org>
In-reply-to
Content
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?
History
Date User Action Args
2019-05-21 19:06:31asvetlovsetrecipients: + asvetlov, cjw296, michael.foord, yselivanov, lisroach, xtreak
2019-05-21 19:06:31asvetlovsetmessageid: <1558465591.83.0.459020555027.issue36996@roundup.psfhosted.org>
2019-05-21 19:06:31asvetlovlinkissue36996 messages
2019-05-21 19:06:31asvetlovcreate