◐ Shell
clean mode source ↗

gh-143939: Fix assignment to `_PyThreadStateImpl.generator_return_kind` by colesbury · Pull Request #143951 · python/cpython

Conversation

@colesbury

@colesbury colesbury commented

Jan 17, 2026

edited by bedevere-app Bot

Loading

…n_kind

The assignment to generator_return_kind has to be after any potentially
escaping calls or it might be overwritten.

johnslavik

Comment on lines +2271 to +2279

class CallGeneratorOnDealloc:
def __del__(self):
def gen():
yield 1
next(gen())

async def coro():
obj = CallGeneratorOnDealloc()
return 42

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little bit smaller in size:

class CallGeneratorOnDealloc:
def __del__(self):
def gen():
yield 1
next(gen())
async def coro():
obj = CallGeneratorOnDealloc()
return 42
class CallGeneratorOnDealloc:
def __del__(self):
next(x for x in [42])
async def coro():
obj = CallGeneratorOnDealloc()

johnslavik

kumaraditya303

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

thunder-coding pushed a commit to thunder-coding/cpython that referenced this pull request

Feb 15, 2026
…rn_kind` (pythongh-143951)

The assignment to generator_return_kind has to be after any potentially
escaping calls to ensure that it's not overwritten.