Skip to content
Draft
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Doc/library/sys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,12 @@ always available.
``cache_tag`` is set to ``None``, it indicates that module caching should
be disabled.

*arch* describes the architecture of the current interpreter runtime system.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"current interpreter runtime system" is wrong--_architecture defines what architecture CPython was built with, not what it's currently running under.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's close. It specifies the architecture it was built to run as, which is independent from both the one it was built on, and the one it's currently running on.

But it's the only one that is specific to the currently running interpreter. So at most, I'd only change this to "the native architecture of the current interpreter", and possibly add "which will usually match the architecture of the current system" (though that's probably more words than it's worth).


.. 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,
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added ``arch`` attribute to :data:`sys.implementation`
to describe the current system platform.
6 changes: 5 additions & 1 deletion PCbuild/pythoncore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,11 @@
<ClCompile Include="..\Python\structmember.c" />
<ClCompile Include="..\Python\symtable.c" />
<ClCompile Include="..\Python\sysmodule.c">
<PreprocessorDefinitions>VPATH="$(PyVPath)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>
ARCH_NAME="$(ArchName)";
VPATH="$(PyVPath)";
%(PreprocessorDefinitions)
</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\Python\thread.c" />
<ClCompile Include="..\Python\traceback.c" />
Expand Down
12 changes: 12 additions & 0 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading