Skip to content

test_track_literals depends on a garbage collection #155728

Open

Description

@serhiy-storchaka

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.

$ ./python -c "import gc; print(gc.is_tracked((1,)))"
True

So test_track_literals passes only if a collection happens between importing the module and running the test. Under regrtest it does not:

$ ./python -m test test_tuple -m test_track_literals
AssertionError: True is not false : (1,)

while ./python -m unittest test.test_tuple.TupleTest.test_track_literals passes.

Untracking tuple constants when the code object is created would let the test keep the stronger check.

Linked PRs

Activity

  1. added
    type-bug
    tests
    3.14
    3.15
    3.16
    on Aug 13, 2026
  2. serhiy-storchaka commented on Aug 13, 2026

    @serhiy-storchaka
    MemberAuthor

    The failing test assertion were added in #140575. cc @vstinner, @efimov-mikhail.

  3. sergey-miryanov commented on Aug 13, 2026

    @sergey-miryanov
    Contributor

    Do you mind I will take this?

  4. added
    interpreter-core
    on Aug 13, 2026
  5. serhiy-storchaka commented on Aug 13, 2026

    @serhiy-storchaka
    MemberAuthor

    You are welcome.

  6. vstinner commented on Aug 13, 2026

    @vstinner
    Member

    Maybe (1,) can be rewritten as x=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.

  7. serhiy-storchaka commented on Aug 13, 2026

    @serhiy-storchaka
    MemberAuthor

    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.

  8. vstinner commented on Aug 13, 2026

    @vstinner
    Member

    Ah thanks, it's good to have a way to reproduce the issue.

  9. sergey-miryanov commented on Aug 24, 2026

    @sergey-miryanov
    Contributor

    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?

    @vstinner @serhiy-storchaka

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

Metadata

Metadata

Labels

3.143.153.16interpreter-coreteststype-bug

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions