Skip to content

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

Closed
@graingert

Description

@graingert

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

Activity

added
type-bugAn unexpected behavior, bug, or error
interpreter-core(Objects, Python, Grammar, and Parser dirs)
3.11only security fixes
3.10only security fixes
3.9only security fixes
3.12only security fixes
3.13bugs and security fixes
on Apr 13, 2024
graingert

graingert commented on Apr 13, 2024

@graingert
ContributorAuthor

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

duaneg commented on May 28, 2025

@duaneg
Contributor

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

added a commit that references this issue on May 28, 2025

pythongh-117852: eagerly check arguments to asyncgen.athrow()

added a commit that references this issue on Jun 2, 2025

gh-117852: fix argument checking of `async_generator.athrow` (#134868)

b6237c3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10only security fixes3.11only security fixes3.12only security fixes3.13bugs and security fixes3.8 (EOL)end of life3.9only security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      asyncgen.athrow() checks args on asyncgen.athrow().send() but should check them on asyncgen.athrow() · Issue #117852 · python/cpython

      Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

      Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant