https://github.com/python/cpython/commit/34f5ae69fe9ab0f5b23311d5c396d0cbb5902913
commit: 34f5ae69fe9ab0f5b23311d5c396d0cbb5902913
branch: main
author: Kirill Podoprigora <[email protected]>
committer: pganssle <[email protected]>
date: 2024-06-08T16:45:57-04:00
summary:
gh-120268: Prohibit passing ``None`` to ``_pydatetime.date.fromtimestamp``
(#120269)
This makes the pure Python implementation consistent with the C implementation.
files:
A Misc/NEWS.d/next/Library/2024-06-08-14-36-40.gh-issue-120268.MNpd1q.rst
M Lib/_pydatetime.py
M Lib/test/datetimetester.py
diff --git a/Lib/_pydatetime.py b/Lib/_pydatetime.py
index b7d569cc41740e..34ccb2da13d0f3 100644
--- a/Lib/_pydatetime.py
+++ b/Lib/_pydatetime.py
@@ -966,6 +966,8 @@ def __new__(cls, year, month=None, day=None):
@classmethod
def fromtimestamp(cls, t):
"Construct a date from a POSIX timestamp (like time.time())."
+ if t is None:
+ raise TypeError("'NoneType' object cannot be interpreted as an
integer")
y, m, d, hh, mm, ss, weekday, jday, dst = _time.localtime(t)
return cls(y, m, d)
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index b80da5697ef865..28f75a803b4e04 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -1336,6 +1336,11 @@ def test_insane_fromtimestamp(self):
self.assertRaises(OverflowError, self.theclass.fromtimestamp,
insane)
+ def test_fromtimestamp_with_none_arg(self):
+ # See gh-120268 for more details
+ with self.assertRaises(TypeError):
+ self.theclass.fromtimestamp(None)
+
def test_today(self):
import time
diff --git
a/Misc/NEWS.d/next/Library/2024-06-08-14-36-40.gh-issue-120268.MNpd1q.rst
b/Misc/NEWS.d/next/Library/2024-06-08-14-36-40.gh-issue-120268.MNpd1q.rst
new file mode 100644
index 00000000000000..d48d43cd047f7a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-06-08-14-36-40.gh-issue-120268.MNpd1q.rst
@@ -0,0 +1,2 @@
+Prohibit passing ``None`` to pure-Python :meth:`datetime.date.fromtimestamp`
+to achieve consistency with C-extension implementation.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]