Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2e3e54a
Add sys.abi_info
zklaus Aug 1, 2025
2ddafa4
📜🤖 Added by blurb_it.
blurb-it[bot] Aug 6, 2025
cdc50c3
Simplify pointer_bits handling
zklaus Aug 7, 2025
6fb25a3
Remove explicit C API function
zklaus Aug 7, 2025
4c3d83d
Make abi_info object a simple namespace with no explicit C API
zklaus Aug 7, 2025
820e002
Cleanup scaffolding
zklaus Aug 7, 2025
918521f
Fix make_abi_info to be static
zklaus Aug 7, 2025
7863651
Add test
zklaus Aug 12, 2025
81d75fc
Fix test
zklaus Aug 12, 2025
41027a3
Add link
zklaus Aug 14, 2025
56726ab
Rename attributes
zklaus Aug 14, 2025
94b7f40
Add better attribute specification to docs
zklaus Aug 21, 2025
6887d6c
Base `debug` on Py_REF_DEBUG
zklaus Aug 21, 2025
7ced683
Add byteorder
zklaus Aug 21, 2025
cc5ae8c
Fix test
zklaus Aug 21, 2025
5c18587
Improve error message in test
zklaus Aug 21, 2025
d025d17
Apply suggestions from code review
zklaus Sep 2, 2025
a089371
Revert "Base `debug` on Py_REF_DEBUG"
zklaus Sep 2, 2025
44ce7c7
Add whatsnew entry for improved sys module
zklaus Sep 2, 2025
8f57f17
Update Python/sysmodule.c
zklaus Sep 3, 2025
77f7b9b
Integrate suggestions from Adam Turner
zklaus Sep 3, 2025
312bff1
Add Windows configuration equivalents
zklaus Sep 4, 2025
ed7b6d9
Fix rst lint
zklaus Sep 4, 2025
15f065a
Use Sphinx markup for attributes
encukou Sep 5, 2025
151eb4c
Merge pull request #3 from encukou/add-sys.abi_info
zklaus Sep 8, 2025
9f5ffae
Merge branch 'main' into add-sys.abi_info
AA-Turner Sep 8, 2025
128b150
Don't use ReST in a C comment
encukou Sep 8, 2025
0506533
docs rephrasing
AA-Turner Sep 8, 2025
c0fcade
Condense the implementation
AA-Turner Sep 8, 2025
87f02ef
Merge branch 'main' into add-sys.abi_info
AA-Turner Sep 8, 2025
8dfbdee
Petr's review
AA-Turner Sep 8, 2025
9547274
Ben's review
AA-Turner Sep 8, 2025
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
2 changes: 2 additions & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(format)
STRUCT_FOR_ID(format_spec)
STRUCT_FOR_ID(frame_buffer)
STRUCT_FOR_ID(free_threaded)
STRUCT_FOR_ID(from_param)
STRUCT_FOR_ID(fromlist)
STRUCT_FOR_ID(fromtimestamp)
Expand Down Expand Up @@ -673,6 +674,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(person)
STRUCT_FOR_ID(pi_factory)
STRUCT_FOR_ID(pid)
STRUCT_FOR_ID(pointer_bits)
STRUCT_FOR_ID(policy)
STRUCT_FOR_ID(pos)
STRUCT_FOR_ID(pos1)
Expand Down
2 changes: 2 additions & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Include/internal/pycore_unicodeobject_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,17 +741,15 @@ def test_thread_info(self):

def test_abi_info(self):
info = sys.abi_info
self.assertEqual(len(info.__dict__), 4)
info_keys = {'pointer_bits', 'free_threaded', 'debug', 'byteorder'}
self.assertEqual(set(vars(info)), info_keys)
pointer_bits = 64 if sys.maxsize > 2**32 else 32
self.assertEqual(info.pointer_bits, pointer_bits)
self.assertEqual(info.free_threaded,
bool(sysconfig.get_config_var('Py_GIL_DISABLED')))
self.assertEqual(info.debug,
bool(sysconfig.get_config_var('Py_DEBUG')))
self.assertEqual(info.byteorder, sys.byteorder)
for attr, flag in [
("free_threaded", "Py_GIL_DISABLED"),
("debug", "Py_DEBUG"),
]:
self.assertEqual(getattr(info, attr, None),
bool(sysconfig.get_config_var(flag)),
f"for {attr}")

@unittest.skipUnless(support.is_emscripten, "only available on Emscripten")
def test_emscripten_info(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Add ``sys.abi_info`` object to make ABI information more easily accessible.
Add :data:`sys.abi_info` object to make ABI information more easily accessible.
39 changes: 16 additions & 23 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3643,33 +3643,30 @@ make_impl_info(PyObject *version_info)
static PyObject *
make_abi_info(void)
{
// New entries should be added when needed for a supported platform, or (for
// enabling an unsupported one) by core dev consensus. Entries should be removed
// following PEP 387.
int res;
PyObject *abi_info, *value, *ns;
abi_info = PyDict_New();
// New entries should be added when needed for a supported platform,
// or by core dev consensus for enabling an unsupported one.

PyObject *value;
PyObject *abi_info = PyDict_New();
if (abi_info == NULL) {
goto error;
return NULL;
}

value = PyLong_FromLong(sizeof(void *) * 8);
if (value == NULL) {
goto error;
}
res = PyDict_SetItemString(abi_info, "pointer_bits", value);
Py_DECREF(value);
if (res < 0) {
if (PyDict_SetItem(abi_info, &_Py_ID(pointer_bits), value) < 0) {
goto error;
}
Py_DECREF(value);

#ifdef Py_GIL_DISABLED
value = Py_True;
#else
value = Py_False;
#endif
res = PyDict_SetItemString(abi_info, "free_threaded", value);
if (res < 0) {
if (PyDict_SetItem(abi_info, &_Py_ID(free_threaded), value) < 0) {
goto error;
}

Expand All @@ -3678,34 +3675,30 @@ make_abi_info(void)
#else
value = Py_False;
#endif
res = PyDict_SetItemString(abi_info, "debug", value);
if (res < 0) {
if (PyDict_SetItem(abi_info, &_Py_ID(debug), value) < 0) {
goto error;
}

#if PY_BIG_ENDIAN
value = PyUnicode_FromString("big");
value = &_Py_ID(big);
#else
value = PyUnicode_FromString("little");
value = &_Py_ID(little);
#endif
if (value == NULL) {
goto error;
}
res = PyDict_SetItemString(abi_info, "byteorder", value);
Py_DECREF(value);
if (res < 0) {
if (PyDict_SetItem(abi_info, &_Py_ID(byteorder), value) < 0) {
goto error;
}

ns = _PyNamespace_New(abi_info);
PyObject *ns = _PyNamespace_New(abi_info);
Py_DECREF(abi_info);
return ns;

error:
Py_DECREF(abi_info);
Py_XDECREF(value);
return NULL;
}


#ifdef __EMSCRIPTEN__

PyDoc_STRVAR(emscripten_info__doc__,
Expand Down
Loading