8000 gh-128509: Add `sys._is_immortal` for identifying immortal objects by ZeroIntensity · Pull Request #128510 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-128509: A 8000 dd 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

Merged
merged 20 commits into from
Jan 31, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Test for sys._is_immortal in the existing case.
  • Loading branch information
ZeroIntensity committed Jan 27, 2025
commit 64c9a5209425a16d7790c428c608924d4634e472
14 changes: 10 additions & 4 deletions Lib/test/test_capi/test_immortal.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import unittest
from test.support import import_helper
import sys

_testcapi = import_helper.import_module('_testcapi')
_testinternalcapi = import_helper.import_module('_testinternalcapi')


class TestUnstableCAPI(unittest.TestCase):
def test_immortal(self):
class TestImmortalAPI(unittest.TestCase):
def immortal_checking(self, func):
# Not extensive
known_immortals = (True, False, None, 0, ())
for immortal in known_immortals:
with self.subTest(immortal=immortal):
self.assertTrue(_testcapi.is_immortal(immortal))
self.assertTrue(func(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))
self.assertFalse(func(non_immortal))

def test_unstable_c_api(self):
self.immortal_checking(_testcapi.is_immortal)
# CRASHES _testcapi.is_immortal(NULL)

def test_sys(self):
self.immortal_checking(sys._is_immortal)
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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.



class TestInternalCAPI(unittest.TestCase):

Expand Down
Loading
0