]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.13] 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:54:19 +0000 (21:54 +0200)
committerGitHub <noreply@github.com>
Thu, 9 Jul 2026 19:54:19 +0000 (15:54 -0400)
commit9a24c1ce4153ca59398f92e5e40e4c335f705059
tree1d38bf1377afde907f8288abd935ecc451bf9c15
parent7994b41154279a2c7d22456a5c200e1fa662b931
[3.13] gh-153406: Raise ValueError, not OverflowError, for out-of-range dates in email.utils.parsedate_to_datetime (GH-153407) (#153433)

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]