Skip to content

Commit 33b5e66

Browse files
committed
change accepted parameter type of sleep and other functions to fix #15313
1 parent 8a363f6 commit 33b5e66

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

stdlib/time.pyi

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import sys
22
from _typeshed import structseq
3-
from typing import Any, Final, Literal, Protocol, final, type_check_only
3+
from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, final, type_check_only
44
from typing_extensions import TypeAlias
55

66
_TimeTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int]
77

8+
if sys.version_info >= (3, 15):
9+
# anticipate on https://github.com/python/cpython/pull/139224
10+
_SupportsFloatOrIndex: TypeAlias = SupportsFloat | SupportsIndex
11+
else:
12+
# before, time functions only accept (subclass of) float, *not* SupportsFloat
13+
_SupportsFloatOrIndex: TypeAlias = float | SupportsIndex
14+
815
altzone: int
916
daylight: int
1017
timezone: int
@@ -68,11 +75,11 @@ class struct_time(structseq[Any | int], _TimeTuple):
6875
def tm_gmtoff(self) -> int: ...
6976

7077
def asctime(time_tuple: _TimeTuple | struct_time = ..., /) -> str: ...
71-
def ctime(seconds: float | None = None, /) -> str: ...
72-
def gmtime(seconds: float | None = None, /) -> struct_time: ...
73-
def localtime(seconds: float | None = None, /) -> struct_time: ...
78+
def ctime(seconds: _SupportsFloatOrIndex | None = None, /) -> str: ...
79+
def gmtime(seconds: _SupportsFloatOrIndex | None = None, /) -> struct_time: ...
80+
def localtime(seconds: _SupportsFloatOrIndex | None = None, /) -> struct_time: ...
7481
def mktime(time_tuple: _TimeTuple | struct_time, /) -> float: ...
75-
def sleep(seconds: float, /) -> None: ...
82+
def sleep(seconds: _SupportsFloatOrIndex, /) -> None: ...
7683
def strftime(format: str, time_tuple: _TimeTuple | struct_time = ..., /) -> str: ...
7784
def strptime(data_string: str, format: str = "%a %b %d %H:%M:%S %Y", /) -> struct_time: ...
7885
def time() -> float: ...

0 commit comments

Comments
 (0)