Skip to content

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

Closed

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

  1. added
    type-bugAn unexpected behavior, bug, or error
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    3.11only security fixes
    3.12only security fixes
    3.13only security fixes
    on Apr 13, 2024
  2. 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
    
  3. 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.

  4. added a commit that references this issue on May 28, 2025
  5. added a commit that references this issue on Jun 2, 2025
  6. added a commit that references this issue on Jul 12, 2025
  7. added a commit that references this issue on Aug 4, 2025
  8. added a commit that references this issue on Aug 19, 2025
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.10 (EOL)end of life3.11only security fixes3.12only security fixes3.13only security fixes3.8 (EOL)end of life3.9 (EOL)end of lifeinterpreter-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