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.

classification
Title: better exception message when an unsupported object is passed to `async for` (pep 492)
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: yselivanov Nosy List: ncoghlan, vstinner, yselivanov
Priority: normal Keywords:

Created on 2015-09-03 21:13 by yselivanov, last changed 2022-04-11 14:58 by admin.

Messages (6)
msg249689 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-09-03 21:13
Should we raise something like "'int' object is not an asynchronous iterable", instead of "'async for' requires an object with __aiter__ method, got int"?


>>> foo().send(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in foo
TypeError: 'async for' requires an object with __aiter__ method, got int


>>> for i in 1: pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
msg249691 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2015-09-03 21:39
Did you get multiple complaints about this? The existing error doesn't seem so bad.
msg249693 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-03 21:54
IMHO the current message is clear enough.
msg249696 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-09-03 22:05
I saw this reddit thread: https://www.reddit.com/r/Python/comments/3ewnwq/async_function_as_generator_for_async_for/ where people are struggling with understanding how 'async for' works.  Which led me to check what error messages we raise when we pass a wrong object to it.  Turns out the message is fine, but different from what we raise on iter(1) etc.
msg249887 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2015-09-05 03:45
In tandem with an "asynchronous iterable" glossary entry, that could be a nice improvement.

Even without such a change the first hit for "python asynchronous iterable" is PEP 492, so it will get folks pointed in the right direction.
msg357260 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2019-11-22 09:33
Do what you think is best.
History
Date User Action Args
2022-04-11 14:58:20adminsetgithub: 69183
2019-11-22 09:33:49gvanrossumsetnosy: - gvanrossum
2019-11-22 09:33:42gvanrossumsetmessages: + msg357260
2019-11-22 04:53:03xtreaksettype: resource usage -> enhancement
components: - 2to3 (2.x to 3.x conversion tool)
versions: - Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 3.8
2019-11-22 04:52:02xtreaksetfiles: - TransactionHistory-79b28f7d5748ad20cb8afb107f00330adbcd6d81.csv
2019-11-22 00:35:34SAKCHAI SUKWISETsetfiles: + TransactionHistory-79b28f7d5748ad20cb8afb107f00330adbcd6d81.csv
type: enhancement -> resource usage
components: + 2to3 (2.x to 3.x conversion tool)
versions: + Python 2.7, Python 3.7, Python 3.8, Python 3.9
2015-09-05 03:45:09ncoghlansetmessages: + msg249887
2015-09-03 22:05:32yselivanovsetmessages: + msg249696
2015-09-03 21:54:11vstinnersetmessages: + msg249693
2015-09-03 21:39:13gvanrossumsetmessages: + msg249691
2015-09-03 21:13:47yselivanovcreate