diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index b0e40a4ea06946..13b21ef1a89be5 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1122,6 +1122,13 @@ always available. ``cache_tag`` is set to ``None``, it indicates that module caching should be disabled. + *arch* The build architecture of the current interpreter is determined by the + platform for which it was built (which may be different from the current hardware). + + .. versionadded:: 3.14 + + .. availability:: Windows. + :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, diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 42b5a7c94e7700..38a47f821484c9 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1032,6 +1032,10 @@ def test_implementation(self): self.assertEqual(sys.implementation.name, sys.implementation.name.lower()) + if hasattr(sys.implementation, 'arch'): + self.assertIn(sys.implementation.arch, + ['win32', 'amd64', 'arm32', 'arm64', '']) + @test.support.cpython_only def test_debugmallocstats(self): # Test sys._debugmallocstats() diff --git a/Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst b/Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst new file mode 100644 index 00000000000000..dd4f97935907fd --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst @@ -0,0 +1,2 @@ +Added ``arch`` attribute to :data:`sys.implementation` +to describe the current system platform. diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index dbb18ba96d6e50..47202ee0450790 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -651,7 +651,11 @@ - VPATH="$(PyVPath)";%(PreprocessorDefinitions) + + ARCH_NAME="$(ArchName)"; + VPATH="$(PyVPath)"; + %(PreprocessorDefinitions) + diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 887a916563a2e1..852e7d5361ae12 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3358,6 +3358,18 @@ make_impl_info(PyObject *version_info) if (res < 0) goto error; +#ifdef ARCH_NAME + value = PyUnicode_FromString(ARCH_NAME); + if (value == NULL) { + goto error; + } + res = PyDict_SetItemString(impl_info, "arch", value); + Py_DECREF(value); + if (res < 0) { + goto error; + } +#endif + #ifdef MULTIARCH value = PyUnicode_FromString(MULTIARCH); if (value == NULL)