Skip to content

Commit b3a20f8

Browse files
committed
Delay annotation eval
1 parent f1aca01 commit b3a20f8

1 file changed

Lines changed: 27 additions & 35 deletions

File tree

trio/_core/_run.py

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,48 @@
1+
from __future__ import annotations
2+
3+
import enum
14
import functools
5+
import gc
26
import itertools
37
import random
48
import select
59
import sys
610
import threading
7-
import gc
11+
import warnings
812
from collections import deque
13+
from collections.abc import Callable
914
from contextlib import contextmanager
10-
import warnings
11-
import enum
12-
1315
from contextvars import copy_context
16+
from heapq import heapify, heappop, heappush
1417
from math import inf
1518
from time import perf_counter
16-
from typing import Any, Deque, NoReturn, TypeVar, TYPE_CHECKING
17-
18-
# An unfortunate name collision here with trio._util.Final
19-
from typing_extensions import Final as FinalT
20-
21-
from sniffio import current_async_library_cvar
19+
from typing import TYPE_CHECKING, Any, NoReturn, TypeVar
2220

2321
import attr
24-
from heapq import heapify, heappop, heappush
25-
from sortedcontainers import SortedDict
2622
from outcome import Error, Outcome, Value, capture
23+
from sniffio import current_async_library_cvar
24+
from sortedcontainers import SortedDict
2725

26+
# An unfortunate name collision here with trio._util.Final
27+
from typing_extensions import Final as FinalT
28+
29+
from .. import _core
30+
from .._util import Final, NoPublicConstructor, coroutine_or_error
31+
from ._asyncgens import AsyncGenerators
2832
from ._entry_queue import EntryQueue, TrioToken
29-
from ._exceptions import TrioInternalError, RunFinishedError, Cancelled
30-
from ._ki import (
31-
LOCALS_KEY_KI_PROTECTION_ENABLED,
32-
KIManager,
33-
enable_ki_protection,
34-
)
33+
from ._exceptions import Cancelled, RunFinishedError, TrioInternalError
34+
from ._instrumentation import Instruments
35+
from ._ki import LOCALS_KEY_KI_PROTECTION_ENABLED, KIManager, enable_ki_protection
3536
from ._multierror import MultiError, concat_tb
37+
from ._thread_cache import start_thread_soon
3638
from ._traps import (
3739
Abort,
38-
wait_task_rescheduled,
39-
cancel_shielded_checkpoint,
4040
CancelShieldedCheckpoint,
4141
PermanentlyDetachCoroutineObject,
4242
WaitTaskRescheduled,
43+
cancel_shielded_checkpoint,
44+
wait_task_rescheduled,
4345
)
44-
from ._asyncgens import AsyncGenerators
45-
from ._thread_cache import start_thread_soon
46-
from ._instrumentation import Instruments
47-
from .. import _core
48-
from .._util import Final, NoPublicConstructor, coroutine_or_error
49-
50-
if sys.version_info < (3, 9):
51-
from typing import Callable
52-
else:
53-
from collections.abc import Callable
5446

5547
if sys.version_info < (3, 11):
5648
from exceptiongroup import BaseExceptionGroup
@@ -1410,7 +1402,7 @@ class Runner:
14101402
# Run-local values, see _local.py
14111403
_locals = attr.ib(factory=dict)
14121404

1413-
runq: Deque[Task] = attr.ib(factory=deque)
1405+
runq: deque[Task] = attr.ib(factory=deque)
14141406
tasks = attr.ib(factory=set)
14151407

14161408
deadlines = attr.ib(factory=Deadlines)
@@ -2530,16 +2522,16 @@ async def checkpoint_if_cancelled():
25302522

25312523

25322524
if sys.platform == "win32":
2533-
from ._io_windows import WindowsIOManager as TheIOManager
25342525
from ._generated_io_windows import *
2526+
from ._io_windows import WindowsIOManager as TheIOManager
25352527
elif sys.platform == "linux" or (not TYPE_CHECKING and hasattr(select, "epoll")):
2536-
from ._io_epoll import EpollIOManager as TheIOManager
25372528
from ._generated_io_epoll import *
2529+
from ._io_epoll import EpollIOManager as TheIOManager
25382530
elif TYPE_CHECKING or hasattr(select, "kqueue"):
2539-
from ._io_kqueue import KqueueIOManager as TheIOManager
25402531
from ._generated_io_kqueue import *
2532+
from ._io_kqueue import KqueueIOManager as TheIOManager
25412533
else: # pragma: no cover
25422534
raise NotImplementedError("unsupported platform")
25432535

2544-
from ._generated_run import *
25452536
from ._generated_instrumentation import *
2537+
from ._generated_run import *

0 commit comments

Comments
 (0)