Bug 2222449

Summary: python 3.12: sys.getrefcount always yields (unsigned int)-1
Product: [Fedora] Fedora Reporter: Jerry James <loganjerry>
Component: python3.12Assignee: Python Maintainers <python-maint>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: unspecified    
Version: rawhideCC: cstratak, mhroncok, python-maint, python-packagers-sig, rjones, swt, thrnciar, vstinner
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-07-12 21:37:57 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jerry James 2023-07-12 19:22:13 UTC
The swig package failed a test during the OCaml 5.0.0 rebuild.  On an x86_64 Fedora 38 machine, with python 3.11:

$ python3
Python 3.11.4 (main, Jun  7 2023, 00:00:00) [GCC 13.1.1 20230511 (Red Hat 13.1.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> x = "hello"
>>> sys.getrefcount(x)
2
>>> y = x
>>> sys.getrefcount(x)
3

On an x86_64 Rawhide machine, with python 3.12:

$ python3
Python 3.12.0b3 (main, Jun 21 2023, 00:00:00) [GCC 13.1.1 20230614 (Red Hat 13.1.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> x = "hello"
>>> sys.getrefcount(x)
4294967295
>>> y = x
>>> sys.getrefcount(x)
4294967295

So (unsigned int)-1 was returned in both cases.  Swig has a test that expects the second sys.getrefcount invocation to return a number 1 higher than the previous invocation.

Reproducible: Always

Steps to Reproduce:
1. Run the python code shown above
2.
3.
Actual Results:  
With python 3.12, sys.getrefcount appears to return a constant.

Expected Results:  
sys.getrefcount should behave like it did in python 3.11.

Comment 1 Miro Hrončok 2023-07-12 20:02:08 UTC
Reproducible also with 3.12.0~b4-1.fc39.

Comment 2 Miro Hrončok 2023-07-12 20:06:53 UTC
Reproducible also with /usr/bin/python3.12d

Comment 3 Scott Talbert 2023-07-12 20:11:09 UTC
Related to PEP 683?  https://peps.python.org/pep-0683/

Comment 4 Scott Talbert 2023-07-12 20:33:02 UTC
I think it's expected behavior with "immortal" objects such as str instances, based on my reading of the PEP?

Comment 5 Miro Hrončok 2023-07-12 21:37:57 UTC
Indeed that seems to be the case.

>>> x = 1
>>> sys.getrefcount(x)
4294967295
>>> x = 100000000000000
>>> sys.getrefcount(x)
2

Comment 6 Jerry James 2023-07-12 21:40:47 UTC
Then it is the swig test that is wrong.  I'll report this to swig upstream.  Thank you, everyone!