summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/_pydatetime.py2
-rw-r--r--Lib/test/datetimetester.py5
-rw-r--r--Misc/NEWS.d/next/Library/2024-06-08-14-36-40.gh-issue-120268.MNpd1q.rst2
3 files changed, 9 insertions, 0 deletions
diff --git a/Lib/_pydatetime.py b/Lib/_pydatetime.py
index b7d569c..34ccb2d 100644
--- a/Lib/_pydatetime.py
+++ b/Lib/_pydatetime.py
@@ -966,6 +966,8 @@ class date:
@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 db6502b..ddd8e02 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -1355,6 +1355,11 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase):
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 0000000..d48d43c
--- /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.