This makes the pure Python implementation consistent with the C implementation.
(cherry picked from commit
34f5ae69fe9ab0f5b23311d5c396d0cbb5902913)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
@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)
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
--- /dev/null
+Prohibit passing ``None`` to pure-Python :meth:`datetime.date.fromtimestamp`
+to achieve consistency with C-extension implementation.