Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better exception message when an unsupported object is passed to async for (pep 492) #69183

Closed
1st1 opened this issue Sep 3, 2015 · 8 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) pending The issue will be closed if no feedback is provided topic-asyncio type-feature A feature request or enhancement

Comments

@1st1
Copy link
Member

1st1 commented Sep 3, 2015

BPO 24995
Nosy @ncoghlan, @vstinner, @1st1

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/1st1'
closed_at = None
created_at = <Date 2015-09-03.21:13:47.658>
labels = ['interpreter-core', 'type-feature', '3.9']
title = 'better exception message when an unsupported object is passed to `async for` (pep 492)'
updated_at = <Date 2019-11-22.09:33:49.517>
user = 'https://github.com/1st1'

bugs.python.org fields:

activity = <Date 2019-11-22.09:33:49.517>
actor = 'gvanrossum'
assignee = 'yselivanov'
closed = False
closed_date = None
closer = None
components = ['Interpreter Core']
creation = <Date 2015-09-03.21:13:47.658>
creator = 'yselivanov'
dependencies = []
files = []
hgrepos = []
issue_num = 24995
keywords = []
message_count = 6.0
messages = ['249689', '249691', '249693', '249696', '249887', '357260']
nosy_count = 3.0
nosy_names = ['ncoghlan', 'vstinner', 'yselivanov']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue24995'
versions = ['Python 3.9']

@1st1
Copy link
Member Author

1st1 commented Sep 3, 2015

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

@1st1 1st1 added the type-feature A feature request or enhancement label Sep 3, 2015
@1st1 1st1 self-assigned this Sep 3, 2015
@1st1 1st1 added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Sep 3, 2015
@gvanrossum
Copy link
Member

Did you get multiple complaints about this? The existing error doesn't seem so bad.

@vstinner
Copy link
Member

vstinner commented Sep 3, 2015

IMHO the current message is clear enough.

@1st1
Copy link
Member Author

1st1 commented Sep 3, 2015

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.

@ncoghlan
Copy link
Contributor

ncoghlan commented Sep 5, 2015

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.

@SAKCHAISUKWISET SAKCHAISUKWISET mannequin added topic-2to3 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes performance Performance or resource usage and removed type-feature A feature request or enhancement labels Nov 22, 2019
@tirkarthi tirkarthi added type-feature A feature request or enhancement and removed topic-2to3 3.7 (EOL) end of life 3.8 only security fixes performance Performance or resource usage labels Nov 22, 2019
@gvanrossum
Copy link
Member

Do what you think is best.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@kumaraditya303
Copy link
Contributor

FWIW the existing message is clear enough and this seems abandoned for over 7 years. I'll close this unless anyone objects otherwise.

@kumaraditya303 kumaraditya303 added pending The issue will be closed if no feedback is provided and removed 3.9 only security fixes labels Sep 29, 2022
@gvanrossum
Copy link
Member

Just close it.

@kumaraditya303 kumaraditya303 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) pending The issue will be closed if no feedback is provided topic-asyncio type-feature A feature request or enhancement
Projects
Status: Done
Development

No branches or pull requests

7 participants