Skip to content

gh-156101: Don't set the result in error in PyLong_AsInt32() - #156727

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:asint
Aug 31, 2026
Merged

vstinner merged 1 commit into
python:mainfrom
vstinner:asint

Conversation

@vstinner

@vstinner vstinner commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

Don't set the result in error in PyLong_AsInt32(), PyLong_AsUInt32(), PyLong_AsInt64() and PyLong_AsUInt64(). Leave the result unchanged in this case.

Don't set the result in error in PyLong_AsInt32(), PyLong_AsUInt32(),
PyLong_AsInt64() and PyLong_AsUInt64(). Leave the result unchanged in
this case.
@vstinner

Copy link
Copy Markdown
Member Author

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. 👍

But what to do with documentation?

@vstinner

Copy link
Copy Markdown
Member Author

But what to do with documentation?

IMO the current documentation already covers the new behavior: "Set an exception and return -1 on error." I don't think that we have to say explicitly that *value is left unchanged on error.

@vstinner
vstinner enabled auto-merge (squash) August 31, 2026 17:40
@vstinner
vstinner merged commit 63f6626 into python:main Aug 31, 2026
64 checks passed
@vstinner
vstinner deleted the asint branch August 31, 2026 17:48
@miss-islington-app

Copy link
Copy Markdown

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Aug 31, 2026

Copy link
Copy Markdown

GH-156728 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Aug 31, 2026
@bedevere-app

bedevere-app Bot commented Aug 31, 2026

Copy link
Copy Markdown

GH-156729 is a backport of this pull request to the 3.14 branch.

@vstinner

Copy link
Copy Markdown
Member Author

Merged, thanks for the review.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Aug 31, 2026
@serhiy-storchaka

Copy link
Copy Markdown
Member

Thank you for fix.

vstinner added a commit that referenced this pull request Aug 31, 2026
…H-156727) (#156729)

gh-156101: Don't set the result in error in PyLong_AsInt32() (GH-156727)

Don't set the result in error in PyLong_AsInt32(), PyLong_AsUInt32(),
PyLong_AsInt64() and PyLong_AsUInt64(). Leave the result unchanged in
this case.
(cherry picked from commit 63f6626)

Co-authored-by: Victor Stinner <vstinner@python.org>
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Sep 12, 2026
…ython#156727)

Don't set the result in error in PyLong_AsInt32(), PyLong_AsUInt32(),
PyLong_AsInt64() and PyLong_AsUInt64(). Leave the result unchanged in
this case.
vstinner added a commit that referenced this pull request Oct 9, 2026
…H-156727) (#156728)

gh-156101: Don't set the result in error in PyLong_AsInt32() (GH-156727)

Don't set the result in error in PyLong_AsInt32(), PyLong_AsUInt32(),
PyLong_AsInt64() and PyLong_AsUInt64(). Leave the result unchanged in
this case.
(cherry picked from commit 63f6626)

Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants