Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9cdb642

Browse files
authored
gh-85432: Harmonise parameter names between C and pure-Python implementations ofdatetime.time.strftime,datetime.datetime.fromtimestamp (#99993)
1 parent09edde9 commit9cdb642

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

‎Lib/datetime.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,8 +1553,7 @@ def fromisoformat(cls, time_string):
15531553
exceptException:
15541554
raiseValueError(f'Invalid isoformat string:{time_string!r}')
15551555

1556-
1557-
defstrftime(self,fmt):
1556+
defstrftime(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
ifnotisinstance(fmt,str):
@@ -1787,14 +1786,14 @@ def _fromtimestamp(cls, t, utc, tz):
17871786
returnresult
17881787

17891788
@classmethod
1790-
deffromtimestamp(cls,t,tz=None):
1789+
deffromtimestamp(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-
returncls._fromtimestamp(t,tzisnotNone,tz)
1796+
returncls._fromtimestamp(timestamp,tzisnotNone,tz)
17981797

17991798
@classmethod
18001799
defutcfromtimestamp(cls,t):

‎Lib/test/datetimetester.py

Lines changed: 9 additions & 0 deletions
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+
deftest_fromtimestamp_keyword_arg(self):
2430+
importtime
2431+
2432+
# gh-85432: The parameter was named "t" in the pure-Python impl.
2433+
self.theclass.fromtimestamp(timestamp=time.time())
2434+
24292435
deftest_utcfromtimestamp(self):
24302436
importtime
24312437

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

3537+
# gh-85432: The parameter was named "fmt" in the pure-Python impl.
3538+
t.strftime(format="%f")
3539+
35313540
deftest_format(self):
35323541
t=self.theclass(1,2,3,4)
35333542
self.assertEqual(t.__format__(''),str(t))
Lines changed: 5 additions & 0 deletions
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)

[8]ページ先頭

©2009-2025 Movatter.jp