colesbury · GitHub

Bug report

Bug description:

Since Python 3.12, generator.close() and generator.gi_frame.clear() do not clear the generator's frame, if the generator is in the FRAME_CREATED state.

The following passes on Python 3.11 and earlier and fails on Python 3.12+

class DetectDeletion:
    deleted = False
    def __del__(self):
        DetectDeletion.deleted = True
def gen(x): yield 1
g = gen(DetectDeletion())
g.close()  # or alternatively: g.gi_frame.clear()
assert DetectDeletion.deleted
del g

Introduced in:

CPython versions tested on:

3.11, 3.12, 3.14, 3.13, 3.15

Operating systems tested on:

No response

Linked PRs

Read the original on github.com ↗