Skip to content

frozenset() created from a set literal is not untracked by the GC #155181

Open

Description

@aisk

gh-140232 made frozensets untracked by the GC when none of their elements can be tracked. However, the compiler's fast path for frozenset({...}) and frozenset({... for ...}) freezes the built set in place with _PySet_Freeze() (INTRINSIC_BUILD_FROZENSET), which skips that check, so the result stays tracked:

>>> import gc
>>> s = {1, 2}
>>> gc.is_tracked(frozenset(s))
False
>>> gc.is_tracked(frozenset({1, 2}))
True

I'm preparing a PR for this.

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    on Aug 4, 2026
  2. added a commit that references this issue on Nov 14, 2026
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