[Python-checkins] gh-85432: Harmonise parameter names between C and pure-Python implementations of `datetime.time.strftime`, `datetime.datetime.fromtimestamp` (#99993)

hauntsaninja webhook-mailer at python.org
Thu Dec 22 16:57:23 EST 2022


https://github.com/python/cpython/commit/9cdb6429971cd8b874ceaeeb04ae2ecdbba42bdb
commit: 9cdb6429971cd8b874ceaeeb04ae2ecdbba42bdb
branch: main
author: Alex Waygood <Alex.Waygood at Gmail.com>
committer: hauntsaninja <12621235+hauntsaninja at users.noreply.github.com>
date: 2022-12-22T15:57:18-06:00
summary:

gh-85432: Harmonise parameter names between C and pure-Python implementations of `datetime.time.strftime`, `datetime.datetime.fromtimestamp` (#99993)

files:
A Misc/NEWS.d/next/Library/2022-12-04-16-12-04.gh-issue-85432.l_ehmI.rst
M Lib/datetime.py
M Lib/test/datetimetester.py

diff --git a/Lib/datetime.py b/Lib/datetime.py
index 1b0c5cb2d1c6..68746de1cabf 100644
--- a/Lib/datetime.py
+++ b/Lib/datetime.py
@@ -1553,8 +1553,7 @@ def fromisoformat(cls, time_string):
         except Exception:
             raise ValueError(f'Invalid isoformat string: {time_string!r}')
 
-
-    def strftime(self, fmt):
+    def strftime(self, format):
         """Format using strftime().  The date part of the timestamp passed
         to underlying strftime should not be used.
         """
@@ -1563,7 +1562,7 @@ def strftime(self, fmt):
         timetuple = (1900, 1, 1,
                      self._hour, self._minute, self._second,
                      0, 1, -1)
-        return _wrap_strftime(self, fmt, timetuple)
+        return _wrap_strftime(self, format, timetuple)
 
     def __format__(self, fmt):
         if not isinstance(fmt, str):
@@ -1787,14 +1786,14 @@ def _fromtimestamp(cls, t, utc, tz):
         return result
 
     @classmethod
-    def fromtimestamp(cls, t, tz=None):
+    def fromtimestamp(cls, timestamp, tz=None):
         """Construct a datetime from a POSIX timestamp (like time.time()).
 
         A timezone info object may be passed in as well.
         """
         _check_tzinfo_arg(tz)
 
-        return cls._fromtimestamp(t, tz is not None, tz)
+        return cls._fromtimestamp(timestamp, tz is not None, tz)
 
     @classmethod
     def utcfromtimestamp(cls, t):
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index 121d973b6d5f..6a1df174a1b9 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -2426,6 +2426,12 @@ def test_fromtimestamp(self):
         got = self.theclass.fromtimestamp(ts)
         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):
         import time
 
@@ -3528,6 +3534,9 @@ def test_strftime(self):
         except UnicodeEncodeError:
             pass
 
+        # gh-85432: The parameter was named "fmt" in the pure-Python impl.
+        t.strftime(format="%f")
+
     def test_format(self):
         t = self.theclass(1, 2, 3, 4)
         self.assertEqual(t.__format__(''), str(t))
diff --git a/Misc/NEWS.d/next/Library/2022-12-04-16-12-04.gh-issue-85432.l_ehmI.rst b/Misc/NEWS.d/next/Library/2022-12-04-16-12-04.gh-issue-85432.l_ehmI.rst
new file mode 100644
index 000000000000..68f5d7c942f5
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-12-04-16-12-04.gh-issue-85432.l_ehmI.rst
@@ -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.



More information about the Python-checkins mailing list