]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-135645: Added `supports_isolated_interpreters` to `sys.implementation`...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 21 Jun 2025 08:21:50 +0000 (10:21 +0200)
committerGitHub <noreply@github.com>
Sat, 21 Jun 2025 08:21:50 +0000 (08:21 +0000)
gh-135645: Added `supports_isolated_interpreters` to `sys.implementation` (GH-135667)
(cherry picked from commit 8ca1e4d846e868a20834cf442c48a3648b558bbe)

Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Doc/library/sys.rst
Lib/test/test_sys.py
Misc/NEWS.d/next/Library/2025-06-18-13-58-13.gh-issue-135645.109nff.rst [new file with mode: 0644]
Python/sysmodule.c

index f8f727f4a23410407e67e1cb3d5db96b22f01b23..1626a89a0731bf17b7a9a5ab0fd1a02d61abdcb8 100644 (file)
@@ -1185,6 +1185,15 @@ 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 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
    an underscore, and are not described here.  Regardless of its contents,
@@ -1194,6 +1203,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
index 577a075a1aaa1bc9edb7a68bdd734fdf4699ad20..ec9da33cf46320c3888ff8950e8fdf1d4be4f950 100644 (file)
@@ -1074,6 +1074,7 @@ class SysModuleTest(unittest.TestCase):
         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,6 +1088,15 @@ class SysModuleTest(unittest.TestCase):
         self.assertEqual(sys.implementation.name,
                          sys.implementation.name.lower())
 
+        # https://peps.python.org/pep-0734
+        sii = sys.implementation.supports_isolated_interpreters
+        self.assertIsInstance(sii, bool)
+        if test.support.check_impl_detail(cpython=True):
+            if test.support.is_emscripten or test.support.is_wasi:
+                self.assertFalse(sii)
+            else:
+                self.assertTrue(sii)
+
     @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 (file)
index 0000000..a7764a0
--- /dev/null
@@ -0,0 +1,2 @@
+Added ``supports_isolated_interpreters`` field to
+:data:`sys.implementation`.
index 7c6fd1d0e2400e34559030a4545ceb5e5d720e57..511b50af7354f735dd07710845eae66adfc22e9f 100644 (file)
@@ -3606,6 +3606,18 @@ make_impl_info(PyObject *version_info)
         goto error;
 #endif
 
+    // PEP-734
+#if defined(__wasi__) || defined(__EMSCRIPTEN__)
+    // It is not enabled on WASM builds just yet
+    value = Py_False;
+#else
+    value = Py_True;
+#endif
+    res = PyDict_SetItemString(impl_info, "supports_isolated_interpreters", value);
+    if (res < 0) {
+        goto error;
+    }
+
     /* dict ready */
 
     ns = _PyNamespace_New(impl_info);