From 9651f6fa04faef408fc49fb6123ba1130a73661b Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Wed, 26 Jan 2022 12:09:31 +0300 Subject: [PATCH] Use better types for `time.get_clock_info` (#7040) --- stdlib/time.pyi | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/stdlib/time.pyi b/stdlib/time.pyi index 6e23b331d..c5ef075a4 100644 --- a/stdlib/time.pyi +++ b/stdlib/time.pyi @@ -1,8 +1,7 @@ import sys from _typeshed import structseq -from types import SimpleNamespace -from typing import Any, Union -from typing_extensions import final +from typing import Any, Protocol, Union +from typing_extensions import Literal, final _TimeTuple = tuple[int, int, int, int, int, int, int, int, int] @@ -80,7 +79,13 @@ def time() -> float: ... if sys.platform != "win32": def tzset() -> None: ... # Unix only -def get_clock_info(name: str) -> SimpleNamespace: ... +class _ClockInfo(Protocol): + adjustable: bool + implementation: str + monotonic: bool + resolution: float + +def get_clock_info(name: Literal["monotonic", "perf_counter", "process_time", "time", "thread_time"]) -> _ClockInfo: ... def monotonic() -> float: ... def perf_counter() -> float: ... def process_time() -> float: ...