Skip to content

Conversation

zklaus
Copy link
Contributor

@zklaus zklaus commented Aug 6, 2025

This adds a new sys.abi_info object to make basic abi information more readily accessible.

The basic idea is to have not just flags as originally envisioned in #133143, but rather a more pythonic object with the required information, following the model of the sys.thread_info and sys.int_info object as suggested in the discussion by @encukou.

gh-133143


📚 Documentation preview 📚: https://cpython-previews--137476.org.readthedocs.build/

@bedevere-app
Copy link

bedevere-app bot commented Aug 6, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Copy link
Member

@encukou encukou left a comment

Choose a reason for hiding this comment

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

This is a big PR!
I'll ask you to simplify (and, alas, throw a lot of the scaffolding work away...)

@zklaus zklaus force-pushed the add-sys.abi_info branch from ab093fc to defb2b2 Compare August 7, 2025 13:09
@zklaus
Copy link
Contributor Author

zklaus commented Aug 7, 2025

Thanks for your review, @encukou! I think I have addressed all of your comments and, as you anticipated, it simplifies things a great deal.

Would you mind taking another look?

@encukou
Copy link
Member

encukou commented Aug 7, 2025

Looks good now, thanks!
It does need a test. (Ideally comparing things to sys.maxsize and sysconfig.get_config_var, which should also serve as guide/validation for what the packaging tools will need to do for earlier Python versions.)

And, of course, it needs deciding on what should go here; but that's for the discussion thread.

@zklaus
Copy link
Contributor Author

zklaus commented Aug 7, 2025

Agreed about the tests and further discussion. I just wanted to stabilize the implementation sufficiently to be sure to write meaningful tests. Thanks again!

@zklaus
Copy link
Contributor Author

zklaus commented Aug 12, 2025

Tests are in place and easily extendable. Let's focus on the discussion and get this in 💪.

@zklaus zklaus marked this pull request as ready for review August 12, 2025 11:39
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

Can you also mention the new sys.abi_info in Doc/whatsnew/3.15.rst document? You should add a new "sys" section in https://docs.python.org/dev/whatsnew/3.15.html#improved-modules

@zklaus zklaus requested a review from AA-Turner as a code owner September 2, 2025 12:39
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@zklaus
Copy link
Contributor Author

zklaus commented Sep 4, 2025

With the latest addition of comments on the Windows side of things, I think I addressed all comments. @AA-Turner apologies again for the rebase snafu. I hope a review is still doable.

@encukou encukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 5, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @encukou for commit ed7b6d9 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F137476%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 5, 2025
@zklaus
Copy link
Contributor Author

zklaus commented Sep 8, 2025

@encukou, I think the two test failures are unrelated to this PR (both from tarfile, fixed in #138626).

Is there anything left that I should do?

@encukou
Copy link
Member

encukou commented Sep 8, 2025

Could you add semantic Sphinx syntax for .. attribute::, from zklaus#3 ? Sorry I didn't link to it on Friday.

With that, I consider this good to merge :)

sys.abi_info: Use Sphinx markup for attributes
@zklaus
Copy link
Contributor Author

zklaus commented Sep 8, 2025

Done, thanks!

AA-Turner and others added 2 commits September 8, 2025 14:29
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
@encukou encukou enabled auto-merge (squash) September 8, 2025 13:50
@AA-Turner
Copy link
Member

oops, I meant to push to my own branch to propose a PR to @zklaus's repo, sorry. Given Petr has enabled auto-merge already I'll propose my changes in a follow-up.

Separately, should we use a named type for abi_info? Currently the repr shows namespace, which could be surprising for users:

❯ .\python.bat
>>> import sys
>>> sys.abi_info
namespace(pointer_bits=64, free_threaded=False, debug=True, byteorder='little')

A

@encukou encukou merged commit 1acb718 into python:main Sep 8, 2025
45 checks passed
@vstinner
Copy link
Member

vstinner commented Sep 8, 2025

Separately, should we use a named type for abi_info?

I don't think that using namespace is a big deal here.

@vstinner
Copy link
Member

vstinner commented Sep 8, 2025

Congrats @zklaus, your PR was merged :-)

@encukou
Copy link
Member

encukou commented Sep 8, 2025

should we use a named type for abi_info?

sys.implementation is a namespace too, and I haven't seen any complaints.
(float_info and such are separate types with iter & getitem for compatibility with long-gone Pythons where these were tuples. The names are nice, but not worth the complexity for new stuff.)

@AA-Turner
Copy link
Member

I realised that one drawback of using SimpleNamespace is that the namespace is not immutable, unlike e.g. sys.version_info, sys.int_info, etc. I'm happy to continue using it given @vstinner & @encukou's comments, but perhaps we should override __setattr__? All the other _info namespaces in sys are immutable, sys.implementation seems to be the exception as far as I can tell.

A

@encukou
Copy link
Member

encukou commented Sep 8, 2025

No need. This is Python; consenting adults; you break it you get to keep the pieces; etc.

You can already set sys.int_info = type(sys.int_info)([5, 8, 23, 864]) for example.

Comment on lines +25 to +26
The available entries are the same on all platforms;
e.g. *pointer_size* is available even on 64-bit-only architectures.
Copy link
Member

Choose a reason for hiding this comment

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

e.g. would have been better spelled out as for example

lkollar pushed a commit to lkollar/cpython that referenced this pull request Sep 9, 2025
This makes information about the interpreter ABI more accessible.

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants