This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: gc.get_referrers behavior change 3.6 to 3.7
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, bryevdv, methane, pitrou
Priority: normal Keywords:

Created on 2018-09-07 16:30 by bryevdv, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg324771 - (view) Author: Bryan (bryevdv) Date: 2018-09-07 16:30
When called on a local object inside a function, gc.get_referrers no longer returns a Frame as one of the references. I could not find anything in the release notes or changeling that indicated that this is an intentional change. 

The following script generates different output when run on Python 3.6 vs Python 3.7 (on linux, OSX, or Windows):

```
# referrers.py
import gc, sys

class FakeMod(object): pass

extra = []

def test():
    mod = FakeMod()
    extra.append(mod)
    referrers = gc.get_referrers(mod)
    print(".".join(str(x) for x in sys.version_info[:3]), ":", len(referrers), referrers)

test()
```

Output:

~ master*
(py37) ❯ python test.py
3.7.0 : 1 [[<__main__.FakeMod object at 0x10b65e320>]]

~ master*
(base) ❯ python test.py
3.6.6 : 2 [[<__main__.FakeMod object at 0x106f3ea90>], <frame object at 0x10684b648>]
msg324819 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2018-09-08 06:10
Likely fallout from 5a625d0aa6a6d9ec6574ee8344b41d63dcb9897e.

get_referrers() doesn't really guarantee anything. It's more of a clever hack based on however the Python GC works at the moment. So, this it probably WONTFIX.
msg324886 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2018-09-09 13:54
Benjamin is right.
This is very implementation detail.  We shouldn't rely on such edge case.
History
Date User Action Args
2022-04-11 14:59:05adminsetgithub: 78789
2018-09-09 13:54:32methanesetstatus: open -> closed
resolution: wont fix
messages: + msg324886

stage: resolved
2018-09-08 15:20:45xiang.zhangsetnosy: + pitrou, methane
2018-09-08 06:10:54benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg324819
2018-09-07 16:30:04bryevdvcreate