Skip to content

gh-154892: Fix PyLong_AsLong() error checks in _zoneinfo - #154901

Open
BHUVANSH855 wants to merge 2 commits into
python:mainfrom
BHUVANSH855:fix-zoneinfo-minus-one
Open

gh-154892: Fix PyLong_AsLong() error checks in _zoneinfo#154901
BHUVANSH855 wants to merge 2 commits into
python:mainfrom
BHUVANSH855:fix-zoneinfo-minus-one

Conversation

@BHUVANSH855

@BHUVANSH855 BHUVANSH855 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix Modules/_zoneinfo.c:get_local_timestamp() to correctly distinguish a legitimate -1 result from PyLong_AsLong() from an actual conversion error by checking PyErr_Occurred(), matching the documented C API behavior and the pure-Python implementation.

The previous implementation treated any -1 return value from PyLong_AsLong() as an error, even when no exception was set. This caused datetime subclasses overriding hour, minute, or second to return -1 to incorrectly raise an exception in the C accelerator.

This PR also adds a regression test covering datetime subclasses whose hour, minute, and second properties return -1.

Issue

Closes issue gh-154892

Comment thread Lib/test/test_zoneinfo/test_zoneinfo.py Outdated
Comment thread Modules/_zoneinfo.c
@BHUVANSH855
BHUVANSH855 requested a review from eendebakpt July 30, 2026 06:29
@johnslavik

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants