https://github.com/python/cpython/commit/ffe0b955a0e9b5e8bf17c1d6488d0a728265f389
commit: ffe0b955a0e9b5e8bf17c1d6488d0a728265f389
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: vstinner <[email protected]>
date: 2026-10-10T21:24:48Z
summary:

[3.14] Use _testlimitedcapi in test_free_threading.test_capi (GH-158935) 
(GH-159146) (#159147)

[3.15] Use _testlimitedcapi in test_free_threading.test_capi (GH-158935) 
(GH-159146)

Use _testlimitedcapi in test_free_threading.test_capi (GH-158935)

Replace ctypes with _testlimitedcapi. ctypes is not always available,
and _testlimitedcapi is a thin wrapper to the C API.

Skip the test if _testlimitedcapi is missing.
(cherry picked from commit c777fe523920db74c2c7563e5febd38e9f6523c1)


(cherry picked from commit 1818fba7e737320b4241fdde095146a4c52c0e63)

Co-authored-by: Victor Stinner <[email protected]>

files:
M Lib/test/test_free_threading/test_capi.py

diff --git a/Lib/test/test_free_threading/test_capi.py 
b/Lib/test/test_free_threading/test_capi.py
index 146d7cfc97adb7..36021eb33d5900 100644
--- a/Lib/test/test_free_threading/test_capi.py
+++ b/Lib/test/test_free_threading/test_capi.py
@@ -1,14 +1,12 @@
-import ctypes
 import sys
 import unittest
 
+from test.support import import_helper
 from test.support import threading_helper
 from test.support.threading_helper import run_concurrently
 
-
-_PyImport_AddModuleRef = ctypes.pythonapi.PyImport_AddModuleRef
-_PyImport_AddModuleRef.argtypes = (ctypes.c_char_p,)
-_PyImport_AddModuleRef.restype = ctypes.py_object
+# Skip the test if the extension is missing
+_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
 
 
 @threading_helper.requires_working_threading()
@@ -20,13 +18,14 @@ def test_pyimport_addmoduleref_thread_safe(self):
         NUM_ITERS = 10
         NTHREADS = 4
 
+        PyImport_AddModuleRef = _testlimitedcapi.PyImport_AddModuleRef
         module_name = f"test_free_threading_addmoduleref_{id(self)}"
         module_name_bytes = module_name.encode()
         sys.modules.pop(module_name, None)
         results = []
 
         def worker():
-            module = _PyImport_AddModuleRef(module_name_bytes)
+            module = PyImport_AddModuleRef(module_name_bytes)
             results.append(module)
 
         for _ in range(NUM_ITERS):

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to