Skip to content

Commit f1aca01

Browse files
committed
Address feedback
1 parent 40b805c commit f1aca01

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

trio/_core/_run.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
from contextvars import copy_context
1414
from math import inf
1515
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
1817

1918
# An unfortunate name collision here with trio._util.Final
2019
from typing_extensions import Final as FinalT
@@ -48,19 +47,23 @@
4847
from .. import _core
4948
from .._util import Final, NoPublicConstructor, coroutine_or_error
5049

50+
if sys.version_info < (3, 9):
51+
from typing import Callable
52+
else:
53+
from collections.abc import Callable
54+
5155
if sys.version_info < (3, 11):
5256
from exceptiongroup import BaseExceptionGroup
5357

54-
T = TypeVar("T")
55-
5658
DEADLINE_HEAP_MIN_PRUNE_THRESHOLD: FinalT = 1000
5759

5860
_NO_SEND: FinalT = object()
5961

62+
FnT = TypeVar("FnT", bound=Callable[..., Any])
6063

6164
# Decorator to mark methods public. This does nothing by itself, but
6265
# trio/_tools/gen_exports.py looks for it.
63-
def _public(fn: T) -> T:
66+
def _public(fn: FnT) -> FnT:
6467
return fn
6568

6669

@@ -122,18 +125,18 @@ class SystemClock:
122125
# Add a large random offset to our clock to ensure that if people
123126
# accidentally call time.perf_counter() directly or start comparing clocks
124127
# 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))
126129

127-
def start_clock(self):
130+
def start_clock(self) -> None:
128131
pass
129132

130133
# In cPython 3, on every platform except Windows, perf_counter is
131134
# exactly the same as time.monotonic; and on Windows, it uses
132135
# QueryPerformanceCounter instead of GetTickCount64.
133-
def current_time(self):
136+
def current_time(self) -> float:
134137
return self.offset + perf_counter()
135138

136-
def deadline_to_sleep_time(self, deadline):
139+
def deadline_to_sleep_time(self, deadline: float) -> float:
137140
return deadline - self.current_time()
138141

139142

0 commit comments

Comments
 (0)