Skip to content

Commit bcb065d

Browse files
committed
pythongh-85432: harmonise parameter names between C and pure-Python implementations of datetime.time.strftime, datetime.datetime.fromtimestamp
1 parent 1012dc1 commit bcb065d

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

Lib/datetime.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1553,8 +1553,7 @@ def fromisoformat(cls, time_string):
15531553
except Exception:
15541554
raise ValueError(f'Invalid isoformat string: {time_string!r}')
15551555

1556-
1557-
def strftime(self, fmt):
1556+
def strftime(self, format):
15581557
"""Format using strftime(). The date part of the timestamp passed
15591558
to underlying strftime should not be used.
15601559
"""
@@ -1563,7 +1562,7 @@ def strftime(self, fmt):
15631562
timetuple = (1900, 1, 1,
15641563
self._hour, self._minute, self._second,
15651564
0, 1, -1)
1566-
return _wrap_strftime(self, fmt, timetuple)
1565+
return _wrap_strftime(self, format, timetuple)
15671566

15681567
def __format__(self, fmt):
15691568
if not isinstance(fmt, str):
@@ -1787,14 +1786,14 @@ def _fromtimestamp(cls, t, utc, tz):
17871786
return result
17881787

17891788
@classmethod
1790-
def fromtimestamp(cls, t, tz=None):
1789+
def fromtimestamp(cls, timestamp, tz=None):
17911790
"""Construct a datetime from a POSIX timestamp (like time.time()).
17921791
17931792
A timezone info object may be passed in as well.
17941793
"""
17951794
_check_tzinfo_arg(tz)
17961795

1797-
return cls._fromtimestamp(t, tz is not None, tz)
1796+
return cls._fromtimestamp(timestamp, tz is not None, tz)
17981797

17991798
@classmethod
18001799
def utcfromtimestamp(cls, t):

Lib/test/datetimetester.py

+9
Original file line numberDiff line numberDiff line change
@@ -2426,6 +2426,12 @@ def test_fromtimestamp(self):
24262426
got = self.theclass.fromtimestamp(ts)
24272427
self.verify_field_equality(expected, got)
24282428

2429+
def test_fromtimestamp_keyword_arg(self):
2430+
import time
2431+
2432+
# gh-85432: The parameter was named "t" in the pure-Python impl.
2433+
self.theclass.fromtimestamp(timestamp=time.time())
2434+
24292435
def test_utcfromtimestamp(self):
24302436
import time
24312437

@@ -3528,6 +3534,9 @@ def test_strftime(self):
35283534
except UnicodeEncodeError:
35293535
pass
35303536

3537+
# gh-85432: The parameter was named "fmt" in the pure-Python impl.
3538+
t.strftime(format="%f")
3539+
35313540
def test_format(self):
35323541
t = self.theclass(1, 2, 3, 4)
35333542
self.assertEqual(t.__format__(''), str(t))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Rename the *fmt* parameter of the pure-Python implementation of
2+
:meth:`datetime.time.strftime` to *format*. Rename the *t* parameter of
3+
:meth:`datetime.datetime.fromtimestamp` to *timestamp*. These changes mean
4+
the parameter names in the pure-Python implementation now match the
5+
parameter names in the C implementation. Patch by Alex Waygood.

0 commit comments

Comments
 (0)