[issue37398] contextlib.ContextDecorator decorating async functions

John Belmonte report at bugs.python.org
Tue Jun 25 08:36:43 EDT 2019


John Belmonte <john at neggie.net> added the comment:

My use case is for a non-async context manager, and if we take track_entry_and_exit as an example that's non-async as well.

The explicit approach (e.g. separate base class for decorators applied to sync vs. async functions) doesn't seem ideal, because it precludes having a single context manager for both cases.  track_entry_and_exit is an example where a context manager would want to decorate both types of functions.

I'm not sure how big of a problem the iscoroutinefunction() limitation is-- in Trio style we don't pass around coroutines by normal functions.  The `async` qualifier exists to make it clear when a function returns a coroutine, and ContextDecorator already doesn't work for the case of a regular function returning a coroutine.  I think the scope here is to enhance ContextDecorator to work with async functions which are properly qualified with `async`.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37398>
_______________________________________


More information about the Python-bugs-list mailing list