]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.14] gh-153406: Raise ValueError, not OverflowError, for out-of-range dates in...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 9 Jul 2026 19:53:49 +0000 (21:53 +0200)
committerGitHub <noreply@github.com>
Thu, 9 Jul 2026 19:53:49 +0000 (15:53 -0400)
commit7a7da86d66e146b82eaac8ccc47584e3c1b38008
tree57b00ec40f42f7eae9bae0d7f5d6a5b6dff59931
parent62c34a62c21eccac8ac88ae130319d3e6d488e28
[3.14] gh-153406: Raise ValueError, not OverflowError, for out-of-range dates in email.utils.parsedate_to_datetime (GH-153407) (#153434)

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 37a26b9b94b147b5d683bfce0ef5a4c2fbc21085)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
Lib/email/utils.py
Lib/test/test_email/test_headerregistry.py
Lib/test/test_email/test_utils.py
Misc/NEWS.d/next/Library/2026-07-09-00-00-00.gh-issue-153406.vyMmB6.rst [new file with mode: 0644]