Skip to content

gh-155176: Don't track frozendicts whose contents can never be tracked by the GC - #155178

Open
aisk wants to merge 1 commit into
python:mainfrom
aisk:frozendict-untrack
Open

gh-155176: Don't track frozendicts whose contents can never be tracked by the GC#155178
aisk wants to merge 1 commit into
python:mainfrom
aisk:frozendict-untrack

Conversation

@aisk

@aisk aisk commented Aug 4, 2026

Copy link
Copy Markdown
Member

Comment thread Lib/test/test_dict.py
self.assertFalse(gc.is_tracked(frozendict.fromkeys('ab', 1)))
self.assertFalse(gc.is_tracked(frozendict({1: 2}) | {3: 4}))

self.assertTrue(gc.is_tracked(frozendict({1: [2]})))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What do you think is it worth to add a test with {1: (2,)}?
And maybe it is worth to add tests with gc-tracked keys and gc-not-tracked values?

Comment thread Lib/test/test_dict.py
# subclasses can create reference cycles, they are always tracked
self.assertTrue(gc.is_tracked(FrozenDict({1: 2})))

# a reference cycle through a tracked frozendict is collectable

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would make this a separate test.

Comment thread Lib/test/test_dict.py
self.assertFalse(gc.is_tracked(frozendict()))
self.assertFalse(gc.is_tracked(frozendict({1: 2})))
self.assertFalse(gc.is_tracked(frozendict.fromkeys('ab', 1)))
self.assertFalse(gc.is_tracked(frozendict({1: 2}) | {3: 4}))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please, test nested frozendicts :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants