Skip to content

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

Open
miss-islington wants to merge 1 commit into
python:3.13from
miss-islington:backport-37a26b9-3.13
Open

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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants