Skip to content

[3.15] gh-153406: Raise ValueError, not OverflowError, for out-of-range dates in email.utils.parsedate_to_datetime (GH-153407)#153435

Merged
bitdancer merged 1 commit into
python:3.15from
miss-islington:backport-37a26b9-3.15
Jul 9, 2026
Merged

[3.15] gh-153406: Raise ValueError, not OverflowError, for out-of-range dates in email.utils.parsedate_to_datetime (GH-153407)#153435
bitdancer merged 1 commit into
python:3.15from
miss-islington:backport-37a26b9-3.15

Conversation

@miss-islington

@miss-islington miss-islington commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

email.utils.parsedate_to_datetime documented that it raises ValueError for an invalid date, but it leaked OverflowError when the parsed year or timezone offset was too large for the datetime and timedelta constructors, and that OverflowError also escaped the modern header parsing path since DateHeader.parse only caught ValueError. Wrap the datetime and timezone construction so an OverflowError is re-raised as a ValueError with the original chained as the cause, which restores the documented contract and lets the existing header handler record an InvalidDateDefect instead of raising.
(cherry picked from commit 37a26b9)

Co-authored-by: tonghuaroot (童话) tonghuaroot@gmail.com

…e dates in email.utils.parsedate_to_datetime (pythonGH-153407)

email.utils.parsedate_to_datetime documented that it raises ValueError for an invalid date, but it leaked OverflowError when the parsed year or timezone offset was too large for the datetime and timedelta constructors, and that OverflowError also escaped the modern header parsing path since DateHeader.parse only caught ValueError. Wrap the datetime and timezone construction so an OverflowError is re-raised as a ValueError with the original chained as the cause, which restores the documented contract and lets the existing header handler record an InvalidDateDefect instead of raising.
(cherry picked from commit 37a26b9)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
@miss-islington miss-islington requested a review from a team as a code owner July 9, 2026 13:59
@bitdancer bitdancer merged commit 4b564b3 into python:3.15 Jul 9, 2026
103 of 105 checks passed
@miss-islington miss-islington deleted the backport-37a26b9-3.15 branch July 9, 2026 19:53
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.

3 participants