Skip to content

Commit

Permalink
Remove deprecated features
Browse files Browse the repository at this point in the history
  • Loading branch information
A5rocks committed Jul 5, 2024
1 parent 5da94bf commit e813d15
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 87 deletions.
11 changes: 0 additions & 11 deletions src/trio/_highlevel_open_tcp_listeners.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from __future__ import annotations

import errno
import math
import sys
from typing import TYPE_CHECKING

import trio
from trio import TaskStatus

from . import socket as tsocket
from ._deprecate import warn_deprecated

if TYPE_CHECKING:
from collections.abc import Awaitable, Callable
Expand Down Expand Up @@ -49,15 +47,6 @@ def _compute_backlog(backlog: int | None) -> int:
# Many systems (Linux, BSDs, ...) store the backlog in a uint16 and are
# missing overflow protection, so we apply our own overflow protection.
# https://github.com/golang/go/issues/5030
if backlog == math.inf:
backlog = None
warn_deprecated(
thing="math.inf as a backlog",
version="0.23.0",
instead="None",
issue=2842,
use_triodeprecationwarning=True,
)
if not isinstance(backlog, int) and backlog is not None:
raise TypeError(f"backlog must be an int or None, not {backlog!r}")
if backlog is None:
Expand Down
12 changes: 0 additions & 12 deletions src/trio/_tests/test_highlevel_open_tcp_listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import trio
from trio import (
SocketListener,
TrioDeprecationWarning,
open_tcp_listeners,
open_tcp_stream,
serve_tcp,
Expand Down Expand Up @@ -387,17 +386,6 @@ async def test_open_tcp_listeners_backlog() -> None:
assert listener.socket.backlog == expected # type: ignore[attr-defined]


async def test_open_tcp_listeners_backlog_inf_warning() -> None:
fsf = FakeSocketFactory(99)
tsocket.set_custom_socket_factory(fsf)
with pytest.warns(TrioDeprecationWarning):
listeners = await open_tcp_listeners(0, backlog=float("inf")) # type: ignore[arg-type]
assert listeners
for listener in listeners:
# `backlog` only exists on FakeSocket
assert listener.socket.backlog == 0xFFFF # type: ignore[attr-defined]


async def test_open_tcp_listeners_backlog_float_error() -> None:
fsf = FakeSocketFactory(99)
tsocket.set_custom_socket_factory(fsf)
Expand Down
31 changes: 4 additions & 27 deletions src/trio/_tests/test_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
CancelScope,
CapacityLimiter,
Event,
TrioDeprecationWarning,
_core,
fail_after,
move_on_after,
Expand Down Expand Up @@ -574,7 +573,7 @@ def release_on_behalf_of(self, borrower: Task) -> None:

# TODO: should CapacityLimiter have an abc or protocol so users can modify it?
# because currently it's `final` so writing code like this is not allowed.
await to_thread_run_sync(lambda: None, limiter=CustomLimiter()) # type: ignore[call-overload]
await to_thread_run_sync(lambda: None, limiter=CustomLimiter()) # type: ignore[arg-type]
assert record == ["acquire", "release"]


Expand All @@ -592,7 +591,7 @@ def release_on_behalf_of(self, borrower: Task) -> NoReturn:
bs = BadCapacityLimiter()

with pytest.raises(ValueError, match="^release on behalf$") as excinfo:
await to_thread_run_sync(lambda: None, limiter=bs) # type: ignore[call-overload]
await to_thread_run_sync(lambda: None, limiter=bs) # type: ignore[arg-type]
assert excinfo.value.__context__ is None
assert record == ["acquire", "release"]
record = []
Expand All @@ -601,7 +600,7 @@ def release_on_behalf_of(self, borrower: Task) -> NoReturn:
# chains with it
d: dict[str, object] = {}
with pytest.raises(ValueError, match="^release on behalf$") as excinfo:
await to_thread_run_sync(lambda: d["x"], limiter=bs) # type: ignore[call-overload]
await to_thread_run_sync(lambda: d["x"], limiter=bs) # type: ignore[arg-type]
assert isinstance(excinfo.value.__context__, KeyError)
assert record == ["acquire", "release"]

Expand Down Expand Up @@ -911,7 +910,7 @@ def __bool__(self) -> bool:
raise NotImplementedError

with pytest.raises(NotImplementedError):
await to_thread_run_sync(int, abandon_on_cancel=BadBool()) # type: ignore[call-overload]
await to_thread_run_sync(int, abandon_on_cancel=BadBool()) # type: ignore[arg-type]


async def test_from_thread_reuses_task() -> None:
Expand Down Expand Up @@ -1098,28 +1097,6 @@ async def child() -> None:
nursery.start_soon(child)


async def test_cancellable_and_abandon_raises() -> None:
with pytest.raises(
ValueError,
match=r"^Cannot set `cancellable` and `abandon_on_cancel` simultaneously\.$",
):
await to_thread_run_sync(bool, cancellable=True, abandon_on_cancel=False) # type: ignore[call-overload]

with pytest.raises(
ValueError,
match=r"^Cannot set `cancellable` and `abandon_on_cancel` simultaneously\.$",
):
await to_thread_run_sync(bool, cancellable=True, abandon_on_cancel=True) # type: ignore[call-overload]


async def test_cancellable_warns() -> None:
with pytest.warns(TrioDeprecationWarning):
await to_thread_run_sync(bool, cancellable=False)

with pytest.warns(TrioDeprecationWarning):
await to_thread_run_sync(bool, cancellable=True)


async def test_wait_all_threads_completed() -> None:
no_threads_left = False
e1 = Event()
Expand Down
39 changes: 2 additions & 37 deletions src/trio/_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import queue as stdlib_queue
import threading
from itertools import count
from typing import TYPE_CHECKING, Generic, TypeVar, overload
from typing import TYPE_CHECKING, Generic, TypeVar

import attrs
import outcome
Expand All @@ -23,7 +23,6 @@
enable_ki_protection,
start_thread_soon,
)
from ._deprecate import warn_deprecated
from ._sync import CapacityLimiter, Event
from ._util import coroutine_or_error

Expand Down Expand Up @@ -244,33 +243,12 @@ def run_in_system_nursery(self, token: TrioToken) -> None:
token.run_sync_soon(self.run_sync)


@overload # Decorator used on function with Coroutine[Any, Any, RetT]
async def to_thread_run_sync( # type: ignore[misc]
sync_fn: Callable[..., RetT],
*args: object,
thread_name: str | None = None,
abandon_on_cancel: bool = False,
limiter: CapacityLimiter | None = None,
) -> RetT: ...


@overload # Decorator used on function with Coroutine[Any, Any, RetT]
async def to_thread_run_sync( # type: ignore[misc]
sync_fn: Callable[..., RetT],
*args: object,
thread_name: str | None = None,
cancellable: bool = False,
limiter: CapacityLimiter | None = None,
) -> RetT: ...


@enable_ki_protection # Decorator used on function with Coroutine[Any, Any, RetT]
async def to_thread_run_sync( # type: ignore[misc]
sync_fn: Callable[..., RetT],
*args: object,
thread_name: str | None = None,
abandon_on_cancel: bool | None = None,
cancellable: bool | None = None,
abandon_on_cancel: bool = False,
limiter: CapacityLimiter | None = None,
) -> RetT:
"""Convert a blocking operation into an async operation using a thread.
Expand Down Expand Up @@ -357,19 +335,6 @@ async def to_thread_run_sync( # type: ignore[misc]
"""
await trio.lowlevel.checkpoint_if_cancelled()
if cancellable is not None:
if abandon_on_cancel is not None:
raise ValueError(
"Cannot set `cancellable` and `abandon_on_cancel` simultaneously."
)
warn_deprecated(
"The `cancellable=` keyword argument to `trio.to_thread.run_sync`",
"0.23.0",
issue=2841,
instead="`abandon_on_cancel=`",
use_triodeprecationwarning=True,
)
abandon_on_cancel = cancellable
# raise early if abandon_on_cancel.__bool__ raises
# and give a new name to ensure mypy knows it's never None
abandon_bool = bool(abandon_on_cancel)
Expand Down

0 comments on commit e813d15

Please sign in to comment.