gh-154892: Fix PyLong_AsLong() error checks in _zoneinfo - #154901
Merged
Conversation
eendebakpt
reviewed
Jul 29, 2026
Member
|
I'll change "Closes: gh-154892" in your PR description to "Closes issue gh-154892", because the use of "closes" keyword would close the issue immediately after this PR is merged and before 3 other backport PRs of your change to our maintenance branches are merged. We want to close the issue after the backport PRs are merged. |
StanFromIreland
approved these changes
Aug 1, 2026
|
Thanks @BHUVANSH855 for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15. |
Member
|
Merged, thanks. |
|
GH-155056 is a backport of this pull request to the 3.15 branch. |
|
GH-155057 is a backport of this pull request to the 3.14 branch. |
|
GH-155058 is a backport of this pull request to the 3.13 branch. |
StanFromIreland
added a commit
that referenced
this pull request
Aug 1, 2026
StanFromIreland
added a commit
that referenced
this pull request
Aug 1, 2026
StanFromIreland
added a commit
that referenced
this pull request
Aug 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fix
Modules/_zoneinfo.c:get_local_timestamp()to correctly distinguish a legitimate-1result fromPyLong_AsLong()from an actual conversion error by checkingPyErr_Occurred(), matching the documented C API behavior and the pure-Python implementation.The previous implementation treated any
-1return value fromPyLong_AsLong()as an error, even when no exception was set. This causeddatetimesubclasses overridinghour,minute, orsecondto return-1to incorrectly raise an exception in the C accelerator.This PR also adds a regression test covering
datetimesubclasses whosehour,minute, andsecondproperties return-1.Issue
Closes issue gh-154892