Skip to content

Commit 1740185

Browse files
committed
Better pass through
- Fix a few typos - Remove unnecessary generic function infrastructure - Deduplicate `from typing import ...` imports - Fix codecov complains
1 parent 6b0c997 commit 1740185

29 files changed

+54
-151
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ jobs:
228228
strategy:
229229
fail-fast: false
230230
matrix:
231-
python: ['pypy-3.11', '3.10', '3.10', '3.11', '3.12', '3.13', '3.14']
231+
python: ['pypy-3.11', '3.10', '3.11', '3.12', '3.13', '3.14']
232232
check_formatting: ['0']
233233
no_test_requirements: ['0']
234234
extra_name: ['']

src/trio/_channel.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,6 @@
4444
P = ParamSpec("P")
4545

4646

47-
def _open_memory_channel(
48-
max_buffer_size: int | float, # noqa: PYI041
49-
) -> tuple[MemorySendChannel[T], MemoryReceiveChannel[T]]:
50-
if max_buffer_size != inf and not isinstance(max_buffer_size, int):
51-
raise TypeError("max_buffer_size must be an integer or math.inf")
52-
if max_buffer_size < 0:
53-
raise ValueError("max_buffer_size must be >= 0")
54-
state: MemoryChannelState[T] = MemoryChannelState(max_buffer_size)
55-
return (
56-
MemorySendChannel[T]._create(state),
57-
MemoryReceiveChannel[T]._create(state),
58-
)
59-
60-
6147
# written as a class so you can say open_memory_channel[int](5)
6248
@final
6349
class open_memory_channel(tuple["MemorySendChannel[T]", "MemoryReceiveChannel[T]"]):
@@ -110,14 +96,21 @@ class open_memory_channel(tuple["MemorySendChannel[T]", "MemoryReceiveChannel[T]
11096
channel (summing over all clones).
11197
* ``tasks_waiting_receive``: The number of tasks blocked in ``receive`` on
11298
this channel (summing over all clones).
113-
11499
"""
115100

116101
def __new__( # type: ignore[misc] # "must return a subtype"
117102
cls,
118103
max_buffer_size: int | float, # noqa: PYI041
119104
) -> tuple[MemorySendChannel[T], MemoryReceiveChannel[T]]:
120-
return _open_memory_channel(max_buffer_size)
105+
if max_buffer_size != inf and not isinstance(max_buffer_size, int):
106+
raise TypeError("max_buffer_size must be an integer or math.inf")
107+
if max_buffer_size < 0:
108+
raise ValueError("max_buffer_size must be >= 0")
109+
state: MemoryChannelState[T] = MemoryChannelState(max_buffer_size)
110+
return (
111+
MemorySendChannel[T]._create(state),
112+
MemoryReceiveChannel[T]._create(state),
113+
)
121114

122115
def __init__(self, max_buffer_size: int | float) -> None: # noqa: PYI041
123116
...

src/trio/_core/_exceptions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
from __future__ import annotations
22

33
from functools import partial
4-
from typing import TYPE_CHECKING, Literal
4+
from typing import TYPE_CHECKING, Literal, TypeAlias
55

66
import attrs
77

88
from trio._util import NoPublicConstructor, final
99

1010
if TYPE_CHECKING:
1111
from collections.abc import Callable
12-
from typing import TypeAlias
1312

1413
from typing_extensions import Self
1514

src/trio/_core/_io_epoll.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import select
55
import sys
66
from collections import defaultdict
7-
from typing import TYPE_CHECKING, Literal
7+
from typing import TYPE_CHECKING, Literal, TypeAlias
88

99
import attrs
1010

@@ -14,8 +14,6 @@
1414
from ._wakeup_socketpair import WakeupSocketpair
1515

1616
if TYPE_CHECKING:
17-
from typing import TypeAlias
18-
1917
from .._core import Abort, RaiseCancelT
2018
from .._file_io import _HasFileNo
2119

src/trio/_core/_io_kqueue.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import select
55
import sys
66
from contextlib import contextmanager
7-
from typing import TYPE_CHECKING, Literal
7+
from typing import TYPE_CHECKING, Literal, TypeAlias
88

99
import attrs
1010
import outcome
@@ -15,7 +15,6 @@
1515

1616
if TYPE_CHECKING:
1717
from collections.abc import Callable, Iterator
18-
from typing import TypeAlias
1918

2019
from .._core import Abort, RaiseCancelT, Task, UnboundedQueue
2120
from .._file_io import _HasFileNo

src/trio/_core/_io_windows.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@
55
import socket
66
import sys
77
from contextlib import contextmanager
8-
from typing import (
9-
TYPE_CHECKING,
10-
Literal,
11-
Protocol,
12-
TypeVar,
13-
cast,
14-
)
8+
from typing import TYPE_CHECKING, Literal, Protocol, TypeAlias, TypeVar, cast
159

1610
import attrs
1711
from outcome import Value
@@ -41,7 +35,6 @@
4135

4236
if TYPE_CHECKING:
4337
from collections.abc import Callable, Iterator
44-
from typing import TypeAlias
4538

4639
from typing_extensions import Buffer
4740

src/trio/_core/_ki.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
import signal
44
import sys
5-
import types
65
import weakref
7-
from typing import TYPE_CHECKING, Generic, Protocol, TypeVar
6+
from typing import TYPE_CHECKING, Generic, Protocol, TypeGuard, TypeVar
87

98
import attrs
109

@@ -14,7 +13,6 @@
1413
if TYPE_CHECKING:
1514
import types
1615
from collections.abc import Callable
17-
from typing import TypeGuard
1816

1917
from typing_extensions import Self
2018
# In ordinary single-threaded Python code, when you hit control-C, it raises

src/trio/_core/_tests/test_guest_mode.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from typing import (
1818
TYPE_CHECKING,
1919
NoReturn,
20+
TypeAlias,
2021
TypeVar,
2122
cast,
2223
)
@@ -32,8 +33,6 @@
3233
from .tutil import gc_collect_harder, restore_unraisablehook
3334

3435
if TYPE_CHECKING:
35-
from typing import TypeAlias
36-
3736
from trio._channel import MemorySendChannel
3837

3938
T = TypeVar("T")

src/trio/_core/_traps.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44

55
import enum
66
import types
7+
from collections.abc import Callable
78

89
# typing.Callable is necessary because collections.abc.Callable breaks
910
# test_static_tool_sees_all_symbols in 3.10.
10-
from typing import TYPE_CHECKING, Any, Callable, NoReturn, cast # noqa: UP035
11+
from typing import (
12+
TYPE_CHECKING,
13+
Any,
14+
NoReturn,
15+
TypeAlias,
16+
cast,
17+
)
1118

1219
import attrs
1320
import outcome
@@ -16,7 +23,6 @@
1623

1724
if TYPE_CHECKING:
1825
from collections.abc import Awaitable, Generator
19-
from typing import TypeAlias
2026

2127
from ._run import Task
2228

src/trio/_core/_windows_cffi.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from __future__ import annotations
22

33
import enum
4-
from typing import TYPE_CHECKING, NewType, NoReturn, Protocol, cast
4+
from typing import TYPE_CHECKING, NewType, NoReturn, Protocol, TypeAlias, cast
55

66
if TYPE_CHECKING:
7-
from typing import TypeAlias
8-
97
import cffi
108

119
CData: TypeAlias = cffi.api.FFI.CData

0 commit comments

Comments
 (0)