|
13 | 13 | from contextvars import copy_context |
14 | 14 | from math import inf |
15 | 15 | from time import perf_counter |
16 | | -from typing import Callable, NoReturn, TypeVar, TYPE_CHECKING |
17 | | -from typing import Deque |
| 16 | +from typing import Any, Deque, NoReturn, TypeVar, TYPE_CHECKING |
18 | 17 |
|
19 | 18 | # An unfortunate name collision here with trio._util.Final |
20 | 19 | from typing_extensions import Final as FinalT |
|
48 | 47 | from .. import _core |
49 | 48 | from .._util import Final, NoPublicConstructor, coroutine_or_error |
50 | 49 |
|
| 50 | +if sys.version_info < (3, 9): |
| 51 | + from typing import Callable |
| 52 | +else: |
| 53 | + from collections.abc import Callable |
| 54 | + |
51 | 55 | if sys.version_info < (3, 11): |
52 | 56 | from exceptiongroup import BaseExceptionGroup |
53 | 57 |
|
54 | | -T = TypeVar("T") |
55 | | - |
56 | 58 | DEADLINE_HEAP_MIN_PRUNE_THRESHOLD: FinalT = 1000 |
57 | 59 |
|
58 | 60 | _NO_SEND: FinalT = object() |
59 | 61 |
|
| 62 | +FnT = TypeVar("FnT", bound=Callable[..., Any]) |
60 | 63 |
|
61 | 64 | # Decorator to mark methods public. This does nothing by itself, but |
62 | 65 | # trio/_tools/gen_exports.py looks for it. |
63 | | -def _public(fn: T) -> T: |
| 66 | +def _public(fn: FnT) -> FnT: |
64 | 67 | return fn |
65 | 68 |
|
66 | 69 |
|
@@ -122,18 +125,18 @@ class SystemClock: |
122 | 125 | # Add a large random offset to our clock to ensure that if people |
123 | 126 | # accidentally call time.perf_counter() directly or start comparing clocks |
124 | 127 | # between different runs, then they'll notice the bug quickly: |
125 | | - offset = attr.ib(factory=lambda: _r.uniform(10000, 200000)) |
| 128 | + offset: float = attr.ib(factory=lambda: _r.uniform(10000, 200000)) |
126 | 129 |
|
127 | | - def start_clock(self): |
| 130 | + def start_clock(self) -> None: |
128 | 131 | pass |
129 | 132 |
|
130 | 133 | # In cPython 3, on every platform except Windows, perf_counter is |
131 | 134 | # exactly the same as time.monotonic; and on Windows, it uses |
132 | 135 | # QueryPerformanceCounter instead of GetTickCount64. |
133 | | - def current_time(self): |
| 136 | + def current_time(self) -> float: |
134 | 137 | return self.offset + perf_counter() |
135 | 138 |
|
136 | | - def deadline_to_sleep_time(self, deadline): |
| 139 | + def deadline_to_sleep_time(self, deadline: float) -> float: |
137 | 140 | return deadline - self.current_time() |
138 | 141 |
|
139 | 142 |
|
|
0 commit comments