]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-153406: Raise ValueError, not OverflowError, for out-of-range dates in email.utils...
authortonghuaroot (童话) <tonghuaroot@gmail.com>
Thu, 9 Jul 2026 13:58:56 +0000 (21:58 +0800)
committerGitHub <noreply@github.com>
Thu, 9 Jul 2026 13:58:56 +0000 (09:58 -0400)
commit37a26b9b94b147b5d683bfce0ef5a4c2fbc21085
treeb14ddcc6b7f16510fcc270035a8fc002bde7694a
parent11f1b70f4c981b781aaa94427dc1fceb637b2187
gh-153406: Raise ValueError, not OverflowError, for out-of-range dates in email.utils.parsedate_to_datetime (#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.
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]