[issue29922] error message when __aexit__ is not async

Tadhg McDonald-Jensen report at bugs.python.org
Mon Mar 27 15:53:36 EDT 2017


Tadhg McDonald-Jensen added the comment:

> This is a specific example of the general problem reported in issue 25538.

Definitely related, although the part of giving an error "... can't be used in 'await' expression" when no await expression is used isn't covered by that thread so I'm not sure I'd call this a direct duplicate.


Currently when __anext__ return a non-awaitable this error is shown:

TypeError: 'async for' received an invalid object from __anext__: NoneType

So having __aenter__ and __aexit__ have similar error messages would be nice.

Would it maybe make sense to implement this as adding an argument to GET_AWAITABLE to indicate whether it was called from await, __anext__, __aenter__ or __aexit__? (or others that may exist in future)  I don't know enough about bytecode to know how it'd compare to an instruction for each case.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29922>
_______________________________________


More information about the Python-bugs-list mailing list