Skip to content

Commit b4a0a0b

Browse files
committed
Fix tests on python3.14t
* Add Py_MOD_GIL_NOT_USED to the C/C++ extension. * Add "t" suffix to the Python version on free-threaded build. * On Python 3.14 and newer, tests call sys._clear_internal_caches() instead of sys._clear_type_cache() to avoid a deprecation warning.
1 parent 442b482 commit b4a0a0b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

tests/test_pythoncapi_compat.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
except ImportError:
2020
# Python 2
2121
faulthandler = None
22+
try:
23+
import sysconfig
24+
except ImportError:
25+
# Python 3.1 and older
26+
sysconfig = None
2227

2328
# test.utils
2429
from utils import run_command, command_stdout
@@ -94,10 +99,13 @@ def _run_tests(tests, verbose):
9499
test_func()
95100

96101

102+
_HAS_CLEAR_INTERNAL_CACHES = hasattr(sys, '_clear_internal_caches')
97103
_HAS_CLEAR_TYPE_CACHE = hasattr(sys, '_clear_type_cache')
98104

99105
def _refleak_cleanup():
100-
if _HAS_CLEAR_TYPE_CACHE:
106+
if _HAS_CLEAR_INTERNAL_CACHES:
107+
sys._clear_internal_caches()
108+
elif _HAS_CLEAR_TYPE_CACHE:
101109
sys._clear_type_cache()
102110
gc.collect()
103111

@@ -134,7 +142,12 @@ def python_version():
134142
python_impl = "PyPy"
135143
else:
136144
python_impl = 'Python'
137-
return "%s %s.%s (%s build)" % (python_impl, ver.major, ver.minor, build)
145+
pyver = "%s.%s" % (ver.major, ver.minor)
146+
if ver >= (3, 13):
147+
if sysconfig.get_config_var('Py_GIL_DISABLED'):
148+
# Free-threaded build
149+
pyver += "t"
150+
return "%s %s (%s build)" % (python_impl, pyver, build)
138151

139152

140153
def run_tests(module_name, lang):

tests/test_pythoncapi_compat_cext.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,6 +2624,9 @@ module_exec(PyObject *module)
26242624
#if PY_VERSION_HEX >= 0x03050000
26252625
static PyModuleDef_Slot module_slots[] = {
26262626
{Py_mod_exec, _Py_CAST(void*, module_exec)},
2627+
#if PY_VERSION_HEX >= 0x030D0000
2628+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
2629+
#endif
26272630
{0, _Py_NULL}
26282631
};
26292632
#endif

0 commit comments

Comments
 (0)