Skip to content

Commit

Permalink
fixes after suggestions from teamspen & coolcat <3
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl committed Oct 19, 2023
1 parent f3e5a36 commit 3c50802
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion trio/_core/_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class _NoValue:


@final
@attr.s(eq=False, hash=False, slots=False)
@attr.s(eq=False, hash=False, slots=True)
class RunVarToken(Generic[T], metaclass=NoPublicConstructor):
_var: RunVar[T] = attr.ib()
previous_value: T | type[_NoValue] = attr.ib(default=_NoValue)
Expand Down
7 changes: 5 additions & 2 deletions trio/_core/_tests/test_guest_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@
import pytest
from outcome import Outcome
from pytest import MonkeyPatch, WarningsRecorder
from typing_extensions import TypeAlias

import trio
import trio.testing
from trio._channel import MemorySendChannel
from trio.abc import Instrument

from ..._util import signal_raise
from .tutil import buggy_pypy_asyncgens, gc_collect_harder, restore_unraisablehook

if TYPE_CHECKING:
from typing_extensions import TypeAlias

T = TypeVar("T")
InHost: TypeAlias = Callable[[object], None]

Expand Down Expand Up @@ -346,7 +349,7 @@ async def get_woken_by_host_deadline(watb_cscope: trio.CancelScope) -> None:
# 'sit_in_wait_all_tasks_blocked', we want the test to
# actually end. So in after_io_wait we schedule a second host
# call to tear things down.
class InstrumentHelper(trio._abc.Instrument):
class InstrumentHelper(Instrument):
def __init__(self) -> None:
self.primed = False

Expand Down
2 changes: 1 addition & 1 deletion trio/_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def done(self) -> bool:

_State = _Enum("_State", ["OK", "BROKEN", "CLOSED"])

# TODO: variance
# invariant
T_Stream = TypeVar("T_Stream", bound=Stream)


Expand Down
16 changes: 9 additions & 7 deletions trio/_tests/test_file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,15 @@ async def test_aclose_cancelled(path: pathlib.Path) -> None:
assert f.closed


async def test_detach_rewraps_asynciobase() -> None:
raw = io.BytesIO()
buffered = io.BufferedReader(raw) # type: ignore[arg-type] # ????????????
async def test_detach_rewraps_asynciobase(tmp_path: pathlib.Path) -> None:
tmp_file = tmp_path / "filename"
tmp_file.touch()
with open(tmp_file, mode="rb", buffering=0) as raw:
buffered = io.BufferedReader(raw)

async_file = trio.wrap_file(buffered)
async_file = trio.wrap_file(buffered)

detached = await async_file.detach()
detached = await async_file.detach()

assert isinstance(detached, AsyncIOWrapper)
assert detached.wrapped is raw
assert isinstance(detached, AsyncIOWrapper)
assert detached.wrapped is raw
3 changes: 2 additions & 1 deletion trio/_tests/test_highlevel_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ async def aclose(self) -> None:
class RecordReceiveStream(ReceiveStream):
record: list[str | tuple[str, int | None]] = attr.ib(factory=list)

async def receive_some(self, max_bytes: int | None = None) -> None: # type: ignore[override]
async def receive_some(self, max_bytes: int | None = None) -> bytes:
self.record.append(("receive_some", max_bytes))
return b""

async def aclose(self) -> None:
self.record.append("aclose")
Expand Down
6 changes: 4 additions & 2 deletions trio/_tests/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
from contextlib import asynccontextmanager, contextmanager
from functools import partial
from ssl import SSLContext
from typing import Any, AsyncIterator, Iterator, NoReturn
from typing import TYPE_CHECKING, Any, AsyncIterator, Iterator, NoReturn

import pytest
from typing_extensions import TypeAlias

from trio import StapledStream
from trio._core import MockClock
Expand Down Expand Up @@ -46,6 +45,9 @@
memory_stream_pair,
)

if TYPE_CHECKING:
from typing_extensions import TypeAlias

# We have two different kinds of echo server fixtures we use for testing. The
# first is a real server written using the stdlib ssl module and blocking
# sockets. It runs in a thread and we talk to it over a real socketpair(), to
Expand Down
4 changes: 3 additions & 1 deletion trio/_tests/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import pytest
from pytest import MonkeyPatch, WarningsRecorder
from typing_extensions import TypeAlias

from .. import (
ClosedResourceError,
Expand All @@ -38,6 +37,9 @@
from ..lowlevel import open_process
from ..testing import MockClock, assert_no_checkpoints, wait_all_tasks_blocked

if TYPE_CHECKING:
from typing_extensions import TypeAlias

if sys.platform == "win32":
SignalType: TypeAlias = None
else:
Expand Down
6 changes: 4 additions & 2 deletions trio/_tests/test_sync.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
from __future__ import annotations

import weakref
from typing import Callable, Union
from typing import TYPE_CHECKING, Callable, Union

import pytest
from typing_extensions import TypeAlias

from .. import _core
from .._sync import *
from .._timeouts import sleep_forever
from ..testing import assert_checkpoints, wait_all_tasks_blocked

if TYPE_CHECKING:
from typing_extensions import TypeAlias


async def test_Event() -> None:
e = Event()
Expand Down
11 changes: 4 additions & 7 deletions trio/_tests/test_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import weakref
from functools import partial
from typing import (
TYPE_CHECKING,
AsyncGenerator,
Awaitable,
Callable,
Expand Down Expand Up @@ -462,12 +461,10 @@ async def test_run_in_worker_thread_limiter(
# Mutating them in-place is OK though (as long as you use proper
# locking etc.).
class state:
if TYPE_CHECKING:
ran: int
high_water: int
running: int
parked: int
pass
ran: int
high_water: int
running: int
parked: int

state.ran = 0
state.high_water = 0
Expand Down
3 changes: 1 addition & 2 deletions trio/testing/_fake_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
)

import attr
from typing_extensions import Buffer, Self

import trio
from trio._util import NoPublicConstructor, final
Expand All @@ -33,7 +32,7 @@
from socket import AddressFamily, SocketKind
from types import TracebackType

from typing_extensions import TypeAlias
from typing_extensions import Buffer, Self, TypeAlias

IPAddress: TypeAlias = Union[ipaddress.IPv4Address, ipaddress.IPv6Address]

Expand Down

0 comments on commit 3c50802

Please sign in to comment.