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 rmlibre
Recipients asvetlov, rmlibre, yselivanov
Date 2019-11-01.17:49:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1572630553.03.0.31312836907.issue38664@roundup.psfhosted.org>
In-reply-to
Content
If a coroutine returns a sequence, a user cannot write this clean code:

>>> await coro()[index]
Or,
>>> await coro()[slice]
Or,
>>> await coro()[key]

This raises a TypeError("'coroutine' object is not subscriptable"). To
solve this on the user side, one must add parentheses, leading to a 
convention of ugly syntax:

>>> (await coro())[...]

Or, hiding the parentesis away in a function

>>> async def index_coroutine(coro=None, index=None):
>>>     return (await coro)[index]
>>> await index_coroutine(coro(), slice(1, 5))

This is gross. It's a bug since it unnecessarily requires unpythonic 
code and throws pythonic code. My suggested patch would be to move the 
evaluation of the await statement higher up on the execution order so 
the former snippets would be valid python syntax. The await statement 
should imply parentheses when square brackets are used, since there is 
no other use case for indexing or subscripting a coroutine. This will
lead to more beautiful code.
History
Date User Action Args
2019-11-01 17:49:13rmlibresetrecipients: + rmlibre, asvetlov, yselivanov
2019-11-01 17:49:13rmlibresetmessageid: <1572630553.03.0.31312836907.issue38664@roundup.psfhosted.org>
2019-11-01 17:49:12rmlibrelinkissue38664 messages
2019-11-01 17:49:12rmlibrecreate