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 ncoghlan
Recipients John Belmonte, Krzysztof Wróblewski, asvetlov, ncoghlan, njs, xtreak, yselivanov
Date 2021-08-01.14:59:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1627829957.39.0.717722415866.issue37398@roundup.psfhosted.org>
In-reply-to
Content
You are correct that this proposal is technically rejected, rather than being a true duplicate of the AsyncContextManager addition.

The core problem with the automatic inference idea is that it isn't possible for the standard library to reliably distinguish at decoration time between "synchronous function that happens to return an awaitable" and "coroutine factory function written as a synchronous function that should nevertheless be treated like a coroutine function".

That ambiguity doesn't exist when ContextDecorator and AsyncContextDecorator are applied to distinct helper functions.

Within a given codebase, you may be able to write a "coroutine argument detection" function that is robust enough for that particular codebase (and iscoroutinefunction() may even be adequate for that purpose), in which case ContextDecorator and AsyncContextDecorator provide the building blocks for implementing the two halves of the solution, leaving only the auto-switching code as project specific.
History
Date User Action Args
2021-08-01 14:59:17ncoghlansetrecipients: + ncoghlan, njs, asvetlov, yselivanov, xtreak, John Belmonte, Krzysztof Wróblewski
2021-08-01 14:59:17ncoghlansetmessageid: <1627829957.39.0.717722415866.issue37398@roundup.psfhosted.org>
2021-08-01 14:59:17ncoghlanlinkissue37398 messages
2021-08-01 14:59:17ncoghlancreate