GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — C API: Use _Py_PACK_VERSION() in Py_LIMITED_API version checks by vstinner · Pull Request #161622 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Nov 8, 2026

Copy link
Copy Markdown
Member

Move _Py_PACK_VERSION() from pymacro.h to patchlevel.h.

PR generated with these shell commands on Linux:

HEADERS=$(find Include -name "*.h")
for minor in $(seq 1 9); do sed -i -e "s#0x030${minor}0000#_Py_PACK_VERSION(3, $minor)#g" $HEADERS; done
sed -i -e "s#0x030[aA]0000#_Py_PACK_VERSION(3, 10)#g" $HEADERS
sed -i -e "s#0x030[bB]0000#_Py_PACK_VERSION(3, 11)#g" $HEADERS
sed -i -e "s#0x030[cC]0000#_Py_PACK_VERSION(3, 12)#g" $HEADERS
sed -i -e "s#0x030[dD]0000#_Py_PACK_VERSION(3, 13)#g" $HEADERS
sed -i -e "s#0x030[eE]0000#_Py_PACK_VERSION(3, 14)#g" $HEADERS
sed -i -e "s#0x030[fF]0000#_Py_PACK_VERSION(3, 15)#g" $HEADERS
sed -i -e "s#0x030a00A7#_Py_PACK_VERSION(3, 10)#g" Include/refcount.h

Manual replacements:

  • 0x03050400 => _Py_PACK_FULL_VERSION(3, 5, 4, 0, 0)
  • 0x03060100 => _Py_PACK_FULL_VERSION(3, 6, 1, 0, 0)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner
Use _Py_PACK_VERSION() in Py_LIMITED_API version checks
ef5ef68
Move _Py_PACK_VERSION() from pymacro.h to patchlevel.h.

PR generated with these shell commands on Linux:

    HEADERS=$(find Include -name "*.h")
    for minor in $(seq 1 9); do sed -i -e "s#0x030${minor}0000#_Py_PACK_VERSION(3, $minor)#g" $HEADERS; done
    sed -i -e "s#0x030[aA]0000#_Py_PACK_VERSION(3, 10)#g" $HEADERS
    sed -i -e "s#0x030[bB]0000#_Py_PACK_VERSION(3, 11)#g" $HEADERS
    sed -i -e "s#0x030[cC]0000#_Py_PACK_VERSION(3, 12)#g" $HEADERS
    sed -i -e "s#0x030[dD]0000#_Py_PACK_VERSION(3, 13)#g" $HEADERS
    sed -i -e "s#0x030[eE]0000#_Py_PACK_VERSION(3, 14)#g" $HEADERS
    sed -i -e "s#0x030[fF]0000#_Py_PACK_VERSION(3, 15)#g" $HEADERS
    sed -i -e "s#0x030a00A7#_Py_PACK_VERSION(3, 10)#g" Include/refcount.h

Manual replacements:

* 0x03050400 => _Py_PACK_FULL_VERSION(3, 5, 4, 0, 0)
* 0x03060100 => _Py_PACK_FULL_VERSION(3, 6, 1, 0, 0)
@vstinner vstinner added the skip issue label Nov 8, 2026
@vstinner
vstinner requested a review from kumaraditya303 as a code owner November 8, 2026 16:22
@vstinner vstinner added the skip news label Nov 8, 2026
@vstinner
vstinner requested review from ZeroIntensity and ericsnowcurrently as code owners November 8, 2026 16:22
@vstinner vstinner added the topic-C-API label Nov 8, 2026
@vstinner
vstinner requested review from FFY00, brettcannon, ncoghlan and warsaw as code owners November 8, 2026 16:22
@bedevere-app bedevere-app Bot added the awaiting core review label Nov 8, 2026
@vstinner

vstinner commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

cc @encukou @serhiy-storchaka

I'm never able to remind the value of hexadecimal version numbers such as 0x030d0000. I have to run a Python REPL to convert 0xd to decimal. _Py_PACK_VERSION(3, 13) avoids this issue, I can directly read the Python version number.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@encukou

encukou commented Nov 9, 2026

Copy link
Copy Markdown
Member

This looks like churn to me -- especially with the pre-3.10 versions.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

To me, Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 9) is more readable than Py_LIMITED_API+0 >= 0x03090000 and there are less risk of typos. I would prefer to have a consistent code style, always use _Py_PACK_VERSION(), for Py_LIMITED_API checks.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ZeroIntensity

ZeroIntensity commented Nov 9, 2026

Copy link
Copy Markdown
Member

I agree that this is a significant readability improvement. I can't read hexadecimals either.

vstinner reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@encukou

encukou commented Nov 10, 2026

Copy link
Copy Markdown
Member

I won't block this. But it's the kind of thing that makes backports annoying.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner mentioned this pull request Nov 10, 2026
3.14: objects de-immortalized by old stable-ABI extensions break truthiness checks in specialized bytecode #158401
Open
@serhiy-storchaka

serhiy-storchaka commented Nov 10, 2026

Copy link
Copy Markdown
Member

Can we at least limit this to 3.10+?

I have no strong opinion. It is a churn, but hexadecimal versions are less readable and more errorprone.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brettcannon
brettcannon removed their request for review November 10, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@kumaraditya303 kumaraditya303 Awaiting requested review from kumaraditya303 kumaraditya303 is a code owner
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@ZeroIntensity ZeroIntensity Awaiting requested review from ZeroIntensity ZeroIntensity is a code owner
@FFY00 FFY00 Awaiting requested review from FFY00 FFY00 is a code owner
@ncoghlan ncoghlan Awaiting requested review from ncoghlan ncoghlan is a code owner
@warsaw warsaw Awaiting requested review from warsaw warsaw is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting core review skip issue skip news topic-C-API

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@vstinner @encukou @ZeroIntensity @serhiy-storchaka
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.