Skip to content

anext(A(), default) crashes when StopAsyncIteration is raised by a synchronous __anext__ #131670

Closed
@picnixz

Description

@picnixz

Crash report

What happened?

Python 3.14.0a6+ (heads/main:0e53038ea82, Mar 24 2025, 14:56:34) [GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
...     def __anext__(self):
...         raise StopAsyncIteration
...
>>> anext(A(), "a")
Segmentation fault (core dumped)

There is no crash with anext(A()) or when directly calling __anext__(). Or when __anext__ is declared with async def, it's fine. Or when __anext__() doesn't raise, it's also fine.

NB: I haven't bisected the change but it might be related to what I wrote in 76ffaef.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Output from running 'python -VV' on the command line:

No response

Linked PRs

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dump

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions