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

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]