|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import enum |
1 | 4 | import functools |
| 5 | +import gc |
2 | 6 | import itertools |
3 | 7 | import random |
4 | 8 | import select |
5 | 9 | import sys |
6 | 10 | import threading |
7 | | -import gc |
| 11 | +import warnings |
8 | 12 | from collections import deque |
| 13 | +from collections.abc import Callable |
9 | 14 | from contextlib import contextmanager |
10 | | -import warnings |
11 | | -import enum |
12 | | - |
13 | 15 | from contextvars import copy_context |
| 16 | +from heapq import heapify, heappop, heappush |
14 | 17 | from math import inf |
15 | 18 | 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 |
22 | 20 |
|
23 | 21 | import attr |
24 | | -from heapq import heapify, heappop, heappush |
25 | | -from sortedcontainers import SortedDict |
26 | 22 | from outcome import Error, Outcome, Value, capture |
| 23 | +from sniffio import current_async_library_cvar |
| 24 | +from sortedcontainers import SortedDict |
27 | 25 |
|
| 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 |
28 | 32 | 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 |
35 | 36 | from ._multierror import MultiError, concat_tb |
| 37 | +from ._thread_cache import start_thread_soon |
36 | 38 | from ._traps import ( |
37 | 39 | Abort, |
38 | | - wait_task_rescheduled, |
39 | | - cancel_shielded_checkpoint, |
40 | 40 | CancelShieldedCheckpoint, |
41 | 41 | PermanentlyDetachCoroutineObject, |
42 | 42 | WaitTaskRescheduled, |
| 43 | + cancel_shielded_checkpoint, |
| 44 | + wait_task_rescheduled, |
43 | 45 | ) |
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 |
54 | 46 |
|
55 | 47 | if sys.version_info < (3, 11): |
56 | 48 | from exceptiongroup import BaseExceptionGroup |
@@ -1410,7 +1402,7 @@ class Runner: |
1410 | 1402 | # Run-local values, see _local.py |
1411 | 1403 | _locals = attr.ib(factory=dict) |
1412 | 1404 |
|
1413 | | - runq: Deque[Task] = attr.ib(factory=deque) |
| 1405 | + runq: deque[Task] = attr.ib(factory=deque) |
1414 | 1406 | tasks = attr.ib(factory=set) |
1415 | 1407 |
|
1416 | 1408 | deadlines = attr.ib(factory=Deadlines) |
@@ -2530,16 +2522,16 @@ async def checkpoint_if_cancelled(): |
2530 | 2522 |
|
2531 | 2523 |
|
2532 | 2524 | if sys.platform == "win32": |
2533 | | - from ._io_windows import WindowsIOManager as TheIOManager |
2534 | 2525 | from ._generated_io_windows import * |
| 2526 | + from ._io_windows import WindowsIOManager as TheIOManager |
2535 | 2527 | elif sys.platform == "linux" or (not TYPE_CHECKING and hasattr(select, "epoll")): |
2536 | | - from ._io_epoll import EpollIOManager as TheIOManager |
2537 | 2528 | from ._generated_io_epoll import * |
| 2529 | + from ._io_epoll import EpollIOManager as TheIOManager |
2538 | 2530 | elif TYPE_CHECKING or hasattr(select, "kqueue"): |
2539 | | - from ._io_kqueue import KqueueIOManager as TheIOManager |
2540 | 2531 | from ._generated_io_kqueue import * |
| 2532 | + from ._io_kqueue import KqueueIOManager as TheIOManager |
2541 | 2533 | else: # pragma: no cover |
2542 | 2534 | raise NotImplementedError("unsupported platform") |
2543 | 2535 |
|
2544 | | -from ._generated_run import * |
2545 | 2536 | from ._generated_instrumentation import * |
| 2537 | +from ._generated_run import * |
0 commit comments