Skip to content

Signature incorrect for Coroutine throw? #9586

Closed as not planned
Closed as not planned
@alicederyn

Description

@alicederyn

I own some code that has been forwarding throw by declaring a three-parameter method with two defaulted to None, but as of py3.11 we have started seeing errors:

TypeError: throw() third argument must be a traceback

This doesn't seem to match the type stubs. Should the second Coroutine.throw overload be changed to remove the final | None?

def throw(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> _T_co: ...


Minimal repro

(Must be run in py3.11)

>>> import asyncio
>>> async def f():
...   await asyncio.sleep(0)
>>> async def g():
...   await asyncio.gather(f(), f())
>>> h = g()
>>> h.send(None)
<stdin>:2: DeprecationWarning: There is no current event loop
<_GatheringFuture pending>
>>> h.throw(ValueError("some error"), None, None)
Traceback (most recent call last):
  ...
TypeError: throw() third argument must be a traceback

Notes:

  • this does not happen if you instead do h = f(), nor if you skip the h.send(None), so there is something important about the asyncio.gather.
  • if you run this in py3.10, you will get ValueError: some error, so this is a behaviour change in 3.11.
  • Possibly this is caused by python/cpython@0a8b8e0 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions