mirror of
https://github.com/python/cpython
synced 2024-10-06 17:55:01 +00:00
[3.12] gh-120268: Prohibit passing `None
to
_pydatetime.date.fromtimestamp
` (GH-120269) (GH-120283)
This makes the pure Python implementation consistent with the C implementation.
(cherry picked from commit 34f5ae69fe
)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
This commit is contained in:
parent
b8845369aa
commit
e123f74513
|
@ -970,6 +970,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)
|
||||
|
||||
|
|
|
@ -1331,6 +1331,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
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Prohibit passing ``None`` to pure-Python :meth:`datetime.date.fromtimestamp`
|
||||
to achieve consistency with C-extension implementation.
|
Loading…
Reference in a new issue