Skip to content
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

gh-120268: Prohibit passing None to _pydatetime.date.fromtimestamp #120269

Merged
merged 2 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/_pydatetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,12 @@ 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
print(self.theclass)
Eclips4 marked this conversation as resolved.
Show resolved Hide resolved
with self.assertRaises(TypeError):
self.theclass.fromtimestamp(None)

def test_today(self):
import time

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Prohibit passing ``None`` to pure-Python :meth:`datetime.date.fromtimestamp`
to achieve consistency with C-extension implementation.
Loading