Skip to content

Commit 116229d

Browse files
authored
datetime: various parameters can now safely be passed as keyword arguments on 3.12+ (#9415)
1 parent d6237d0 commit 116229d

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

stdlib/datetime.pyi

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ class date:
7070
@property
7171
def day(self) -> int: ...
7272
def ctime(self) -> str: ...
73-
def strftime(self, __format: str) -> str: ...
73+
# On <3.12, the name of the parameter in the pure-Python implementation
74+
# didn't match the name in the C implementation,
75+
# meaning it is only *safe* to pass it as a keyword argument on 3.12+
76+
if sys.version_info >= (3, 12):
77+
def strftime(self, format: str) -> str: ...
78+
else:
79+
def strftime(self, __format: str) -> str: ...
80+
7481
def __format__(self, __fmt: str) -> str: ...
7582
def isoformat(self) -> str: ...
7683
def timetuple(self) -> struct_time: ...
@@ -140,7 +147,14 @@ class time:
140147
def isoformat(self, timespec: str = ...) -> str: ...
141148
@classmethod
142149
def fromisoformat(cls: type[Self], __time_string: str) -> Self: ...
143-
def strftime(self, __format: str) -> str: ...
150+
# On <3.12, the name of the parameter in the pure-Python implementation
151+
# didn't match the name in the C implementation,
152+
# meaning it is only *safe* to pass it as a keyword argument on 3.12+
153+
if sys.version_info >= (3, 12):
154+
def strftime(self, format: str) -> str: ...
155+
else:
156+
def strftime(self, __format: str) -> str: ...
157+
144158
def __format__(self, __fmt: str) -> str: ...
145159
def utcoffset(self) -> timedelta | None: ...
146160
def tzname(self) -> str | None: ...
@@ -233,11 +247,16 @@ class datetime(date):
233247
def tzinfo(self) -> _TzInfo | None: ...
234248
@property
235249
def fold(self) -> int: ...
236-
# The first parameter in `fromtimestamp` is actually positional-or-keyword,
237-
# but it is named "timestamp" in the C implementation and "t" in the Python implementation,
238-
# so it is only truly *safe* to pass it as a positional argument.
239-
@classmethod
240-
def fromtimestamp(cls: type[Self], __timestamp: float, tz: _TzInfo | None = ...) -> Self: ...
250+
# On <3.12, the name of the first parameter in the pure-Python implementation
251+
# didn't match the name in the C implementation,
252+
# meaning it is only *safe* to pass it as a keyword argument on 3.12+
253+
if sys.version_info >= (3, 12):
254+
@classmethod
255+
def fromtimestamp(cls: type[Self], timestamp: float, tz: _TzInfo | None = ...) -> Self: ...
256+
else:
257+
@classmethod
258+
def fromtimestamp(cls: type[Self], __timestamp: float, tz: _TzInfo | None = ...) -> Self: ...
259+
241260
@classmethod
242261
def utcfromtimestamp(cls: type[Self], __t: float) -> Self: ...
243262
if sys.version_info >= (3, 8):

0 commit comments

Comments
 (0)