Skip to content

GH-74866: Fix utils.parsedate_to_datetime raising exception on None #93945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/email/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ def make_msgid(idstring=None, domain=None):


def parsedate_to_datetime(data):
if data is None:
return None
parsed_date_tz = _parsedate_tz(data)
if parsed_date_tz is None:
raise ValueError('Invalid date value or format "%s"' % str(data))
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_email/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def test_parsedate_to_datetime_with_invalid_raises_valueerror(self):
with self.subTest(dtstr=dtstr):
self.assertRaises(ValueError, utils.parsedate_to_datetime, dtstr)

def test_parsedate_to_datetime_with_None_returns_None(self):
self.assertIsNone(utils.parsedate_to_datetime(None))

class LocaltimeTests(unittest.TestCase):

def test_localtime_is_tz_aware_daylight_true(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :meth:`utils.parsedate_to_datetime` raising exception on ``None``. It now returns ``None`` instead.