Skip to content

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

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

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