diff --git a/stdlib/time.pyi b/stdlib/time.pyi index 5665efbba69d..64a009318894 100644 --- a/stdlib/time.pyi +++ b/stdlib/time.pyi @@ -1,10 +1,17 @@ import sys from _typeshed import structseq -from typing import Any, Final, Literal, Protocol, final, type_check_only +from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, final, type_check_only from typing_extensions import TypeAlias _TimeTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int] +if sys.version_info >= (3, 15): + # anticipate on https://github.com/python/cpython/pull/139224 + _SupportsFloatOrIndex: TypeAlias = SupportsFloat | SupportsIndex +else: + # before, time functions only accept (subclass of) float, *not* SupportsFloat + _SupportsFloatOrIndex: TypeAlias = float | SupportsIndex + altzone: int daylight: int timezone: int @@ -68,11 +75,11 @@ class struct_time(structseq[Any | int], _TimeTuple): def tm_gmtoff(self) -> int: ... def asctime(time_tuple: _TimeTuple | struct_time = ..., /) -> str: ... -def ctime(seconds: float | None = None, /) -> str: ... -def gmtime(seconds: float | None = None, /) -> struct_time: ... -def localtime(seconds: float | None = None, /) -> struct_time: ... +def ctime(seconds: _SupportsFloatOrIndex | None = None, /) -> str: ... +def gmtime(seconds: _SupportsFloatOrIndex | None = None, /) -> struct_time: ... +def localtime(seconds: _SupportsFloatOrIndex | None = None, /) -> struct_time: ... def mktime(time_tuple: _TimeTuple | struct_time, /) -> float: ... -def sleep(seconds: float, /) -> None: ... +def sleep(seconds: _SupportsFloatOrIndex, /) -> None: ... def strftime(format: str, time_tuple: _TimeTuple | struct_time = ..., /) -> str: ... def strptime(data_string: str, format: str = "%a %b %d %H:%M:%S %Y", /) -> struct_time: ... def time() -> float: ...