Skip to content

[3.14] change in behaviour in gc.get_referrers(some_local) #125603

Description

@graingert

Bug report

Bug description:

import gc

async def demo():
    class A:
        pass

    a = A()
    print(gc.get_referrers(a))


try:
    demo().send(None)
except StopIteration as e:
    print(f"{e.value=}")

on 3.11-3.13 this prints:

[]
e.value=None

on 3.14 this prints:

[<coroutine object demo at 0x7d00fff85000>]
e.value=None

this makes gc.get_referrers less useful in detecting cyclic garbage where I'd like to be able to make the assertion that the current frame is the only referrer to an Exception.

the alternative is to hold a weak reference to the object, delete the object and see if the weak reference is dead with the gc disabled. But then I don't get any debug information in my failing test of why the object is still alive.

CPython versions tested on:

3.14, CPython main branch

Operating systems tested on:

Linux

note: @markshannon asked me to open this issue

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    3.14bugs and security fixes
    on Oct 16, 2024
  2. added
    triagedThe issue has been accepted as valid by a triager.
    on Oct 16, 2024
  3. graingert commented on Oct 16, 2024

    @graingert
    ContributorAuthor

    The behavior change was caused by this PR #124392

  4. kumaraditya303 commented on Jul 25, 2025

    @kumaraditya303
    Contributor

    The behavior change is undesirable and breaks tests of many projects, should this be release blocker @hugovk ?

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

Metadata

Metadata

Assignees

Labels

3.14bugs and security fixestriagedThe issue has been accepted as valid by a triager.type-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions