-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-128509: Add PyUnstable_IsImmortal for finding immortal objects
#129182
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
Changes from 14 commits
58ac265
8a64537
4b55134
6bddf33
412a42b
21cf2c4
8d20c00
831626c
422edf9
6014587
48c974c
dd19a02
99e897f
0448daf
5b949b1
d1c9b1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,21 @@ def test_immortal_builtins(self): | |
| for obj in ([], {}, set()): | ||
| self.assertFalse(_testinternalcapi.is_static_immortal(obj)) | ||
|
|
||
| def test_immortal(self): | ||
| # Not extensive | ||
| known_immortals = (True, False, None, 0, ()) | ||
| for immortal in known_immortals: | ||
| with self.subTest(immortal=immortal): | ||
| self.assertTrue(_testcapi.is_immortal(immortal)) | ||
|
|
||
| # Some arbitrary mutable objects | ||
| non_immortals = (object(), self, [object()]) | ||
| for non_immortal in non_immortals: | ||
| with self.subTest(non_immortal=non_immortal): | ||
| self.assertFalse(_testcapi.is_immortal(non_immortal)) | ||
|
|
||
ZeroIntensity marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # CRASHES _testcapi.is_immortal(NULL) | ||
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Add :c:func:`PyUnstable_IsImmortal` for determining whether an object is | ||
| :term:`immortal`. |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -131,13 +131,22 @@ pyobject_enable_deferred_refcount(PyObject *self, PyObject *obj) | |||||||
| return PyLong_FromLong(result); | ||||||||
| } | ||||||||
|
|
||||||||
|
|
||||||||
| static PyObject * | ||||||||
| is_immortal(PyObject *self, PyObject *op) | ||||||||
|
||||||||
| { | ||||||||
| return PyBool_FromLong(PyUnstable_IsImmortal(op)); | ||||||||
|
||||||||
| return PyBool_FromLong(PyUnstable_IsImmortal(op)); | |
| NULLABLE(op) | |
| return PyLong_FromLong(PyUnstable_IsImmortal(op)); |
This allows to test with NULL, and check if the result is not 0 or 1.
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 think it makes sense to crash with NULL.
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.
Does
_testcapi.is_immortal(NULL)crash? If yes, add a comment, otherwise add a test.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.
And ideally an
assertto the implementation (as “executable documentation”).