Skip to content

Signature incorrect for Coroutine throw? #9586

Closed as not planned
Closed as not planned

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 ?

Activity

  1. srittau commented on Jan 25, 2023

    @srittau
    Collaborator

    I couldn't find anything about this in the release notes. I suspect this is actually a bug in Python 3.11.

  2. hauntsaninja commented on Jan 25, 2023

    @hauntsaninja
    Collaborator

    Can confirm that this behaviour is changed by the commit you mention python/cpython@0a8b8e0

  3. hauntsaninja commented on Jan 25, 2023

    @hauntsaninja
    Collaborator

    Not sure why it was changed, possibly unintentionally since the PR is missing a news entry. Let me open an issue against CPython...

  4. srittau commented on Jan 25, 2023

    @srittau
    Collaborator

    This has now been fixed in cpython main and a backport PR for 3.11 is open. I don't think we need to do anything here. Thanks, @alicederyn for opening the issue and @hauntsaninja for fixing it in CPython!

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions