Skip to content

asyncgen.athrow() checks args on asyncgen.athrow().send() but should check them on asyncgen.athrow() #117852

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

Closed
graingert opened this issue Apr 13, 2024 · 2 comments
Labels
3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes 3.12 only security fixes 3.13 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@graingert
Copy link
Contributor

graingert commented Apr 13, 2024

Bug report

Bug description:

async def agen():
    return
    yield


try:
    athrow = agen().athrow()
    athrow.close()
except TypeError:
    print("good")
else:
    print("bad")

output:

bad

CPython versions tested on:

3.8, 3.9, 3.10, 3.11, 3.12, 3.13, CPython main branch

Operating systems tested on:

Linux

Linked PRs

@graingert graingert added type-bug An unexpected behavior, bug, or error interpreter-core (Objects, Python, Grammar, and Parser dirs) 3.11 only security fixes 3.10 only security fixes 3.9 only security fixes 3.8 (EOL) end of life 3.12 only security fixes 3.13 bugs and security fixes labels Apr 13, 2024
@graingert
Copy link
Contributor Author

to get the error you have to actually await the coroutine:

async def agen():
    return
    yield


athrow = agen().athrow()
athrow.send(None)

output:

Traceback (most recent call last):
  File "/home/graingert/projects/cpython/demo.py", line 7, in <module>
    athrow.send(None)
    ~~~~~~~~~~~^^^^^^
TypeError: athrow expected at least 1 argument, got 0

@duaneg
Copy link
Contributor

duaneg commented May 28, 2025

Fixing this would be a change in behaviour, but it is hard to imagine it breaking any working code.

duaneg added a commit to duaneg/cpython that referenced this issue May 28, 2025
At present the arguments to asyncgen.athrow() are not checked until the
coroutine is awaited. Unpack them on coroutine creation instead, so they are
checked immediately.
kumaraditya303 added a commit that referenced this issue Jun 2, 2025
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes 3.12 only security fixes 3.13 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy