Skip to content

generator.close() doesn't clear frame on newly created generators #142766

Closed

Description

@colesbury

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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    on Dec 15, 2025
  2. colesbury commented on Dec 15, 2025

    @colesbury
    ContributorAuthor

    cc @markshannon - I think this is a bug, but I want to check in case this was an intentional behavior change.

  3. markshannon commented on Dec 16, 2025

    @markshannon
    Member

    It's a bug.
    Want to fix it or shall I?

  4. colesbury commented on Dec 16, 2025

    @colesbury
    ContributorAuthor

    I can make the PR

  5. added 3 commits that reference this issue on Dec 16, 2025
  6. added a commit that references this issue on Dec 17, 2025
  7. added 3 commits that reference this issue on Dec 17, 2025
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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions