Repository navigation
test_track_literals depends on a garbage collection #155728
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errortestsTests in the Lib/test dirTests in the Lib/test dir3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixes
on Aug 13, 2026 The failing test assertion were added in #140575. cc @vstinner, @efimov-mikhail.
Do you mind I will take this?
- addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on Aug 13, 2026 You are welcome.
Maybe
(1,)can be rewritten asx=1; (x,)to avoid storing the tuple as a constant.while ./python -m unittest test.test_tuple.TupleTest.test_track_literals passes.
I understand that this issue is more theorical since it's not possible to get a failure when running
test_tuple.You can get failure by running
./python -m test test_tuple -m test_track_literals.It means that the test asserts wrong condition. The result depends on previously executed code, it is not invariant.
Ah thanks, it's good to have a way to reproduce the issue.
There are two aspects to this problem: one with flowgraph optimizations (the CFG should produce untracked tuples where possible), and the second with marshal (since optimization results are cached in
__pycache__).I'd like to open two separate PRs — one for flowgraph + tupleobject changes, one for marshal.
Does that work?
Reacted by Mikhail Efimov
Bug report
_not_tracked_instantly()requires the tuple to be untracked without a collection. This holds for tuples created at run time, but tuple constants are created tracked and are only untracked by_PyTuple_MaybeUntrack(), which is called only from the collector.So
test_track_literalspasses only if a collection happens between importing the module and running the test. Under regrtest it does not:while
./python -m unittest test.test_tuple.TupleTest.test_track_literalspasses.Untracking tuple constants when the code object is created would let the test keep the stronger check.
Linked PRs