From 0566a7c5368938a02ee5fa8f176b402e7af070dc Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 18 Jun 2025 13:58:37 +0300 Subject: [PATCH 1/8] gh-135645: Added `supports_isolated_interpreters` to `sys.implementation` --- Doc/library/sys.rst | 6 ++++++ Lib/test/test_sys.py | 5 +++++ .../Library/2025-06-18-13-58-13.gh-issue-135645.109nff.rst | 2 ++ Python/sysmodule.c | 5 +++++ 4 files changed, 18 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-06-18-13-58-13.gh-issue-135645.109nff.rst diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 71f9999464ab52..774586212c4a12 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1185,6 +1185,9 @@ always available. Unless explicitly noted otherwise, all variables are read-only ``cache_tag`` is set to ``None``, it indicates that module caching should be disabled. + *supports_isolated_interpreters* is a boolean value, whether + this implementation supports :pep:`734`. It is always ``True`` for CPython. + :data:`sys.implementation` may contain additional attributes specific to the Python implementation. These non-standard attributes must start with an underscore, and are not described here. Regardless of its contents, @@ -1194,6 +1197,9 @@ always available. Unless explicitly noted otherwise, all variables are read-only .. versionadded:: 3.3 + .. versionchanged:: 3.14 + Added ``supports_isolated_interpreters`` field. + .. note:: The addition of new required attributes must go through the normal PEP diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 39e62027f03e5a..f31a61d58e52cd 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1087,6 +1087,11 @@ def test_implementation(self): self.assertEqual(sys.implementation.name, sys.implementation.name.lower()) + @test.support.cpython_only + def test_supports_isolated_interpreters(self): + # https://peps.python.org/pep-0734 + self.assertIs(sys.implementation.supports_isolated_interpreters, True) + @test.support.cpython_only def test_debugmallocstats(self): # Test sys._debugmallocstats() diff --git a/Misc/NEWS.d/next/Library/2025-06-18-13-58-13.gh-issue-135645.109nff.rst b/Misc/NEWS.d/next/Library/2025-06-18-13-58-13.gh-issue-135645.109nff.rst new file mode 100644 index 00000000000000..a7764a0105b8b3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-06-18-13-58-13.gh-issue-135645.109nff.rst @@ -0,0 +1,2 @@ +Added ``supports_isolated_interpreters`` field to +:data:`sys.implementation`. diff --git a/Python/sysmodule.c b/Python/sysmodule.c index e5ae841d195d4f..1e2e545cb68e09 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3602,6 +3602,11 @@ make_impl_info(PyObject *version_info) goto error; #endif + res = PyDict_SetItemString(impl_info, "supports_isolated_interpreters", + Py_NewRef(Py_True)); // PEP-734 + if (res < 0) + goto error; + /* dict ready */ ns = _PyNamespace_New(impl_info); From 31c3cf6daba1897f167d72b17d7cb890bd527a56 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 18 Jun 2025 16:21:47 +0300 Subject: [PATCH 2/8] Address review --- Lib/test/test_sys.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index f31a61d58e52cd..63023d7bf5f202 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1074,6 +1074,7 @@ def test_implementation(self): self.assertHasAttr(sys.implementation, 'version') self.assertHasAttr(sys.implementation, 'hexversion') self.assertHasAttr(sys.implementation, 'cache_tag') + self.assertHasAttr(sys.implementation, 'supports_isolated_interpreters') version = sys.implementation.version self.assertEqual(version[:2], (version.major, version.minor)) @@ -1087,10 +1088,10 @@ def test_implementation(self): self.assertEqual(sys.implementation.name, sys.implementation.name.lower()) - @test.support.cpython_only - def test_supports_isolated_interpreters(self): # https://peps.python.org/pep-0734 - self.assertIs(sys.implementation.supports_isolated_interpreters, True) + self.assertIsInstance(sys.implementation.supports_isolated_interpreters, bool) + if test.support.check_impl_detail(cpython=True): + self.assertIs(sys.implementation.supports_isolated_interpreters, True) @test.support.cpython_only def test_debugmallocstats(self): From 7e9c4b5eff80eabbe6914b6cae6ccf4ced77a2c7 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 18 Jun 2025 16:22:11 +0300 Subject: [PATCH 3/8] Address review --- Python/sysmodule.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 1e2e545cb68e09..a091a626406dc2 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3604,8 +3604,9 @@ make_impl_info(PyObject *version_info) res = PyDict_SetItemString(impl_info, "supports_isolated_interpreters", Py_NewRef(Py_True)); // PEP-734 - if (res < 0) + if (res < 0) { goto error; + } /* dict ready */ From 2becd71e3d23a53258bf9998d2cae9b7f43ef3df Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 18 Jun 2025 22:18:22 +0300 Subject: [PATCH 4/8] Update Doc/library/sys.rst Co-authored-by: Eric Snow --- Doc/library/sys.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 774586212c4a12..c2faec1fe2f9a0 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1186,7 +1186,12 @@ always available. Unless explicitly noted otherwise, all variables are read-only be disabled. *supports_isolated_interpreters* is a boolean value, whether - this implementation supports :pep:`734`. It is always ``True`` for CPython. + this implementation supports multiple isolated interpreters. + It is ``True`` for CPython on most platforms. Platforms with + this support implement the low-level :mod:`!_interpreters` module. + + .. seealso: + :pep:`684`, :pep:`734`, and :mod:`concurrent.interpreters`. :data:`sys.implementation` may contain additional attributes specific to the Python implementation. These non-standard attributes must start with From 028b49830789006c526ad12574ef8ef203379a9b Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 18 Jun 2025 22:46:41 +0300 Subject: [PATCH 5/8] Address review --- Doc/library/sys.rst | 7 ++++--- Lib/test/test_sys.py | 12 ++++++++++-- Python/sysmodule.c | 13 +++++++++++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index c2faec1fe2f9a0..8bcf29249a7572 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1189,9 +1189,10 @@ always available. Unless explicitly noted otherwise, all variables are read-only this implementation supports multiple isolated interpreters. It is ``True`` for CPython on most platforms. Platforms with this support implement the low-level :mod:`!_interpreters` module. - - .. seealso: - :pep:`684`, :pep:`734`, and :mod:`concurrent.interpreters`. + + .. seealso:: + + :pep:`684`, :pep:`734`, and :mod:`concurrent.interpreters`. :data:`sys.implementation` may contain additional attributes specific to the Python implementation. These non-standard attributes must start with diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 63023d7bf5f202..06d86203e1aacc 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1089,9 +1089,17 @@ def test_implementation(self): sys.implementation.name.lower()) # https://peps.python.org/pep-0734 - self.assertIsInstance(sys.implementation.supports_isolated_interpreters, bool) + sii = sys.implementation.supports_isolated_interpreters + self.assertIsInstance(sii, bool) if test.support.check_impl_detail(cpython=True): - self.assertIs(sys.implementation.supports_isolated_interpreters, True) + if ( + test.support.is_apple_mobile + or test.support.is_emscripten + or test.support.is_wasi + ): + self.assertFalse(sii) + else: + self.assertTrue(sii) @test.support.cpython_only def test_debugmallocstats(self): diff --git a/Python/sysmodule.c b/Python/sysmodule.c index a091a626406dc2..1a7afaf438c950 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3602,8 +3602,17 @@ make_impl_info(PyObject *version_info) goto error; #endif - res = PyDict_SetItemString(impl_info, "supports_isolated_interpreters", - Py_NewRef(Py_True)); // PEP-734 + // PEP-734 +#if defined(__wasi__) || defined(__EMSCRIPTEN__) + // It is not enabled on WASM builds just yet + value = Py_NewRef(Py_False); +#elif defined(__APPLE__) && defined(TARGET_OS_IPHONE) + // It is not enabled on iOS just yet + value = Py_NewRef(Py_False); +#else + value = Py_NewRef(Py_True); +#endif + res = PyDict_SetItemString(impl_info, "supports_isolated_interpreters", value); if (res < 0) { goto error; } From a0fd949301d1f0e05023c06f01f9293858570ef7 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 18 Jun 2025 23:06:15 +0300 Subject: [PATCH 6/8] Fix CI --- Python/sysmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 1a7afaf438c950..efbf15b37f8a48 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3606,7 +3606,7 @@ make_impl_info(PyObject *version_info) #if defined(__wasi__) || defined(__EMSCRIPTEN__) // It is not enabled on WASM builds just yet value = Py_NewRef(Py_False); -#elif defined(__APPLE__) && defined(TARGET_OS_IPHONE) +#elif defined(__APPLE__) && defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE // It is not enabled on iOS just yet value = Py_NewRef(Py_False); #else From 5fe139c66ebdba3058c1b22709d93dd960a86862 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 19 Jun 2025 09:48:51 +0300 Subject: [PATCH 7/8] Address review --- Python/sysmodule.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index efbf15b37f8a48..4ca317a938757c 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3605,12 +3605,12 @@ make_impl_info(PyObject *version_info) // PEP-734 #if defined(__wasi__) || defined(__EMSCRIPTEN__) // It is not enabled on WASM builds just yet - value = Py_NewRef(Py_False); + value = Py_False; #elif defined(__APPLE__) && defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE // It is not enabled on iOS just yet - value = Py_NewRef(Py_False); + value = Py_False; #else - value = Py_NewRef(Py_True); + value = Py_True; #endif res = PyDict_SetItemString(impl_info, "supports_isolated_interpreters", value); if (res < 0) { From 144b169bbd5ed0ab4038fd1d2ed0ac0fd2967292 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Fri, 20 Jun 2025 09:41:50 +0300 Subject: [PATCH 8/8] Tests pass on iOS --- Lib/test/test_sys.py | 6 +----- Python/sysmodule.c | 3 --- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 06d86203e1aacc..f3fcd4f72ac652 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1092,11 +1092,7 @@ def test_implementation(self): sii = sys.implementation.supports_isolated_interpreters self.assertIsInstance(sii, bool) if test.support.check_impl_detail(cpython=True): - if ( - test.support.is_apple_mobile - or test.support.is_emscripten - or test.support.is_wasi - ): + if test.support.is_emscripten or test.support.is_wasi: self.assertFalse(sii) else: self.assertTrue(sii) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 4ca317a938757c..4ab8d921cc3ab8 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3606,9 +3606,6 @@ make_impl_info(PyObject *version_info) #if defined(__wasi__) || defined(__EMSCRIPTEN__) // It is not enabled on WASM builds just yet value = Py_False; -#elif defined(__APPLE__) && defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE - // It is not enabled on iOS just yet - value = Py_False; #else value = Py_True; #endif