-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-128509: Add sys._is_immortal
for identifying immortal objects
#128510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Lib/test/test_capi/test_immortal.py
Outdated
# CRASHES _testcapi.is_immortal(NULL) | ||
|
||
def test_sys(self): | ||
self.immortal_checking(sys._is_immortal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sys functions must be checked in test_sys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally moved the test from test_sys
to test_immortal
so we could re-use the test case, but I've reverted it now. Are you ok with the redundancy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with redundancy. test_capi can be skipped if _testcapi is missing. It's not the case for test_sys. Both tests are useful.
Python/sysmodule.c
Outdated
sys__is_immortal_impl(PyObject *module, PyObject *op) | ||
/*[clinic end generated code: output=c2f5d6a80efb8d1a input=83733fc356c78475]*/ | ||
{ | ||
return _Py_IsImmortal(op); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using PyUnstable_IsImmortal()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two are pretty similar. Would you prefer I use the unstable API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to use the public unstable API, yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. IMO it makes sense to have a way in Python to check if an object is immortal. Otherwise, developers are confused by surprising sys.getrefcount()
values.
Python/sysmodule.c
Outdated
@@ -955,7 +955,6 @@ sys_intern_impl(PyObject *module, PyObject *s) | |||
} | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated change, I suggest to leave this empty line :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
…cts (python#128510) Co-authored-by: Kumar Aditya <kumaraditya@python.org>
FWIW, I'm basing most of this off
sys._is_interned
.📚 Documentation preview 📚: https://cpython-previews--128510.org.readthedocs.build/en/128510/library/sys.html#sys._is_immortal