Skip to content

Commit af921d5

Browse files
authored
Merge branch 'master' into named_threads
2 parents 4cb23de + b3a729d commit af921d5

6 files changed

Lines changed: 41 additions & 36 deletions

File tree

test-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pexpect==4.8.0
7777
# via ipython
7878
pickleshare==0.7.5
7979
# via ipython
80-
platformdirs==2.5.3
80+
platformdirs==2.5.4
8181
# via
8282
# black
8383
# pylint

trio/_core/_ki.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
from __future__ import annotations
2+
13
import inspect
24
import signal
35
import sys
46
from functools import wraps
7+
from typing import TYPE_CHECKING
58

69
import attr
710

811
from .._util import is_main_thread
912

10-
if False:
13+
if TYPE_CHECKING:
1114
from typing import Any, TypeVar, Callable
1215

1316
F = TypeVar("F", bound=Callable[..., Any])
@@ -54,7 +57,7 @@
5457
#
5558
# If this raises a KeyboardInterrupt, it might be because the coroutine got
5659
# interrupted and has unwound... or it might be the KeyboardInterrupt
57-
# arrived just *after* 'send' returned, so the coroutine is still running
60+
# arrived just *after* 'send' returned, so the coroutine is still running,
5861
# but we just lost the message it sent. (And worse, in our actual task
5962
# runner, the send is hidden inside a utility function etc.)
6063
#
@@ -170,10 +173,10 @@ def wrapper(*args, **kwargs):
170173
return decorator
171174

172175

173-
enable_ki_protection = _ki_protection_decorator(True) # type: Callable[[F], F]
176+
enable_ki_protection: Callable[[F], F] = _ki_protection_decorator(True)
174177
enable_ki_protection.__name__ = "enable_ki_protection"
175178

176-
disable_ki_protection = _ki_protection_decorator(False) # type: Callable[[F], F]
179+
disable_ki_protection: Callable[[F], F] = _ki_protection_decorator(False)
177180
disable_ki_protection.__name__ = "disable_ki_protection"
178181

179182

trio/_subprocess.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ class Process(AsyncResource, metaclass=NoPublicConstructor):
121121

122122
def __init__(self, popen, stdin, stdout, stderr):
123123
self._proc = popen
124-
self.stdin = stdin # type: Optional[SendStream]
125-
self.stdout = stdout # type: Optional[ReceiveStream]
126-
self.stderr = stderr # type: Optional[ReceiveStream]
124+
self.stdin: Optional[SendStream] = stdin
125+
self.stdout: Optional[ReceiveStream] = stdout
126+
self.stderr: Optional[ReceiveStream] = stderr
127127

128-
self.stdio = None # type: Optional[StapledStream]
128+
self.stdio: Optional[StapledStream] = None
129129
if self.stdin is not None and self.stdout is not None:
130130
self.stdio = StapledStream(self.stdin, self.stdout)
131131

@@ -368,9 +368,9 @@ async def open_process(
368368
"on UNIX systems"
369369
)
370370

371-
trio_stdin = None # type: Optional[ClosableSendStream]
372-
trio_stdout = None # type: Optional[ClosableReceiveStream]
373-
trio_stderr = None # type: Optional[ClosableReceiveStream]
371+
trio_stdin: Optional[ClosableSendStream] = None
372+
trio_stdout: Optional[ClosableReceiveStream] = None
373+
trio_stderr: Optional[ClosableReceiveStream] = None
374374
# Close the parent's handle for each child side of a pipe; we want the child to
375375
# have the only copy, so that when it exits we can read EOF on our side. The
376376
# trio ends of pipes will be transferred to the Process object, which will be

trio/_util.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
# coding: utf-8
2-
31
# Little utilities we use internally
42

53
from abc import ABCMeta
64
import os
75
import signal
8-
import sys
9-
import pathlib
10-
from functools import wraps, update_wrapper
6+
from functools import update_wrapper
117
import typing as t
128
import threading
139
import collections
@@ -17,7 +13,7 @@
1713

1814
# Equivalent to the C function raise(), which Python doesn't wrap
1915
if os.name == "nt":
20-
# On windows, os.kill exists but is really weird.
16+
# On Windows, os.kill exists but is really weird.
2117
#
2218
# If you give it CTRL_C_EVENT or CTRL_BREAK_EVENT, it tries to deliver
2319
# those using GenerateConsoleCtrlEvent. But I found that when I tried
@@ -36,7 +32,7 @@
3632
# OTOH, if you pass os.kill any *other* signal number... then CPython
3733
# just calls TerminateProcess (wtf).
3834
#
39-
# So, anyway, os.kill is not so useful for testing purposes. Instead
35+
# So, anyway, os.kill is not so useful for testing purposes. Instead,
4036
# we use raise():
4137
#
4238
# https://msdn.microsoft.com/en-us/library/dwwzkt4c.aspx
@@ -226,7 +222,7 @@ def fix_one(qualname, name, obj):
226222
mod = getattr(obj, "__module__", None)
227223
if mod is not None and mod.startswith("trio."):
228224
obj.__module__ = module_name
229-
# Modules, unlike everything else in Python, put fully-qualitied
225+
# Modules, unlike everything else in Python, put fully-qualified
230226
# names into their __name__ attribute. We check for "." to avoid
231227
# rewriting these.
232228
if hasattr(obj, "__name__") and "." not in obj.__name__:
@@ -277,11 +273,11 @@ class Final(ABCMeta):
277273
class SomeClass(metaclass=Final):
278274
pass
279275
280-
The metaclass will ensure that no sub class can be created.
276+
The metaclass will ensure that no subclass can be created.
281277
282278
Raises
283279
------
284-
- TypeError if a sub class is created
280+
- TypeError if a subclass is created
285281
"""
286282

287283
def __new__(cls, name, bases, cls_namespace):
@@ -305,14 +301,14 @@ class NoPublicConstructor(Final):
305301
class SomeClass(metaclass=NoPublicConstructor):
306302
pass
307303
308-
The metaclass will ensure that no sub class can be created, and that no instance
304+
The metaclass will ensure that no subclass can be created, and that no instance
309305
can be initialized.
310306
311307
If you try to instantiate your class (SomeClass()), a TypeError will be thrown.
312308
313309
Raises
314310
------
315-
- TypeError if a sub class or an instance is created.
311+
- TypeError if a subclass or an instance is created.
316312
"""
317313

318314
def __call__(cls, *args, **kwargs):
@@ -333,7 +329,7 @@ def name_asyncgen(agen):
333329
try:
334330
module = agen.ag_frame.f_globals["__name__"]
335331
except (AttributeError, KeyError):
336-
module = "<{}>".format(agen.ag_code.co_filename)
332+
module = f"<{agen.ag_code.co_filename}>"
337333
try:
338334
qualname = agen.__qualname__
339335
except AttributeError:

trio/testing/_sequencer.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
from __future__ import annotations
2+
13
from collections import defaultdict
24
from contextlib import asynccontextmanager
5+
from typing import TYPE_CHECKING
36

47
import attr
58

69
from .. import _core
710
from .. import _util
811
from .. import Event
912

10-
if False:
11-
from typing import DefaultDict, Set
13+
if TYPE_CHECKING:
14+
from collections.abc import AsyncIterator
1215

1316

1417
@attr.s(eq=False, hash=False)
@@ -52,14 +55,14 @@ async def main():
5255
5356
"""
5457

55-
_sequence_points = attr.ib(
58+
_sequence_points: defaultdict[int, Event] = attr.ib(
5659
factory=lambda: defaultdict(Event), init=False
57-
) # type: DefaultDict[int, Event]
58-
_claimed = attr.ib(factory=set, init=False) # type: Set[int]
59-
_broken = attr.ib(default=False, init=False)
60+
)
61+
_claimed: set[int] = attr.ib(factory=set, init=False)
62+
_broken: bool = attr.ib(default=False, init=False)
6063

6164
@asynccontextmanager
62-
async def __call__(self, position: int):
65+
async def __call__(self, position: int) -> AsyncIterator[None]:
6366
if position in self._claimed:
6467
raise RuntimeError("Attempted to re-use sequence point {}".format(position))
6568
if self._broken:

trio/tests/test_windows_pipes.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
import os
55
import sys
6+
from typing import Any
7+
from typing import Tuple
8+
69
import pytest
710

811
from .._core.tests.tutil import gc_collect_harder
@@ -15,12 +18,12 @@
1518
from asyncio.windows_utils import pipe
1619
else:
1720
pytestmark = pytest.mark.skip(reason="windows only")
18-
pipe = None # type: Any
19-
PipeSendStream = None # type: Any
20-
PipeReceiveStream = None # type: Any
21+
pipe: Any = None
22+
PipeSendStream: Any = None
23+
PipeReceiveStream: Any = None
2124

2225

23-
async def make_pipe() -> "Tuple[PipeSendStream, PipeReceiveStream]":
26+
async def make_pipe() -> Tuple[PipeSendStream, PipeReceiveStream]:
2427
"""Makes a new pair of pipes."""
2528
(r, w) = pipe()
2629
return PipeSendStream(w), PipeReceiveStream(r)

0 commit comments

Comments
 (0)