mirror of https://github.com/python/cpython
gh-85432: Harmonise parameter names between C and pure-Python implementations of `datetime.time.strftime`, `datetime.datetime.fromtimestamp` (#99993)
This commit is contained in:
parent
09edde95f4
commit
9cdb642997
|
@ -1553,8 +1553,7 @@ class time:
|
||||||
except Exception:
|
except Exception:
|
||||||
raise ValueError(f'Invalid isoformat string: {time_string!r}')
|
raise ValueError(f'Invalid isoformat string: {time_string!r}')
|
||||||
|
|
||||||
|
def strftime(self, format):
|
||||||
def strftime(self, fmt):
|
|
||||||
"""Format using strftime(). The date part of the timestamp passed
|
"""Format using strftime(). The date part of the timestamp passed
|
||||||
to underlying strftime should not be used.
|
to underlying strftime should not be used.
|
||||||
"""
|
"""
|
||||||
|
@ -1563,7 +1562,7 @@ class time:
|
||||||
timetuple = (1900, 1, 1,
|
timetuple = (1900, 1, 1,
|
||||||
self._hour, self._minute, self._second,
|
self._hour, self._minute, self._second,
|
||||||
0, 1, -1)
|
0, 1, -1)
|
||||||
return _wrap_strftime(self, fmt, timetuple)
|
return _wrap_strftime(self, format, timetuple)
|
||||||
|
|
||||||
def __format__(self, fmt):
|
def __format__(self, fmt):
|
||||||
if not isinstance(fmt, str):
|
if not isinstance(fmt, str):
|
||||||
|
@ -1787,14 +1786,14 @@ class datetime(date):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fromtimestamp(cls, t, tz=None):
|
def fromtimestamp(cls, timestamp, tz=None):
|
||||||
"""Construct a datetime from a POSIX timestamp (like time.time()).
|
"""Construct a datetime from a POSIX timestamp (like time.time()).
|
||||||
|
|
||||||
A timezone info object may be passed in as well.
|
A timezone info object may be passed in as well.
|
||||||
"""
|
"""
|
||||||
_check_tzinfo_arg(tz)
|
_check_tzinfo_arg(tz)
|
||||||
|
|
||||||
return cls._fromtimestamp(t, tz is not None, tz)
|
return cls._fromtimestamp(timestamp, tz is not None, tz)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def utcfromtimestamp(cls, t):
|
def utcfromtimestamp(cls, t):
|
||||||
|
|
|
@ -2426,6 +2426,12 @@ class TestDateTime(TestDate):
|
||||||
got = self.theclass.fromtimestamp(ts)
|
got = self.theclass.fromtimestamp(ts)
|
||||||
self.verify_field_equality(expected, got)
|
self.verify_field_equality(expected, got)
|
||||||
|
|
||||||
|
def test_fromtimestamp_keyword_arg(self):
|
||||||
|
import time
|
||||||
|
|
||||||
|
# gh-85432: The parameter was named "t" in the pure-Python impl.
|
||||||
|
self.theclass.fromtimestamp(timestamp=time.time())
|
||||||
|
|
||||||
def test_utcfromtimestamp(self):
|
def test_utcfromtimestamp(self):
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -3528,6 +3534,9 @@ class TestTime(HarmlessMixedComparison, unittest.TestCase):
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# gh-85432: The parameter was named "fmt" in the pure-Python impl.
|
||||||
|
t.strftime(format="%f")
|
||||||
|
|
||||||
def test_format(self):
|
def test_format(self):
|
||||||
t = self.theclass(1, 2, 3, 4)
|
t = self.theclass(1, 2, 3, 4)
|
||||||
self.assertEqual(t.__format__(''), str(t))
|
self.assertEqual(t.__format__(''), str(t))
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
Rename the *fmt* parameter of the pure-Python implementation of
|
||||||
|
:meth:`datetime.time.strftime` to *format*. Rename the *t* parameter of
|
||||||
|
:meth:`datetime.datetime.fromtimestamp` to *timestamp*. These changes mean
|
||||||
|
the parameter names in the pure-Python implementation now match the
|
||||||
|
parameter names in the C implementation. Patch by Alex Waygood.
|
Loading…
Reference in New Issue