Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #2940

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
- id: sort-simple-yaml
files: .pre-commit-config.yaml
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.1
rev: 24.1.1
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
Expand Down
1 change: 1 addition & 0 deletions docs/source/typevars.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

See https://github.com/sphinx-doc/sphinx/issues/7722 also.
"""

from __future__ import annotations

import re
Expand Down
1 change: 1 addition & 0 deletions src/trio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Trio - A friendly Python library for async concurrency and I/O
"""

from __future__ import annotations

from typing import TYPE_CHECKING
Expand Down
6 changes: 3 additions & 3 deletions src/trio/_core/_generated_io_epoll.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
__all__ = ["notify_closing", "wait_readable", "wait_writable"]


async def wait_readable(fd: (int | _HasFileNo)) -> None:
async def wait_readable(fd: int | _HasFileNo) -> None:
"""Block until the kernel reports that the given object is readable.

On Unix systems, ``fd`` must either be an integer file descriptor,
Expand Down Expand Up @@ -47,7 +47,7 @@ async def wait_readable(fd: (int | _HasFileNo)) -> None:
raise RuntimeError("must be called from async context") from None


async def wait_writable(fd: (int | _HasFileNo)) -> None:
async def wait_writable(fd: int | _HasFileNo) -> None:
"""Block until the kernel reports that the given object is writable.

See `wait_readable` for the definition of ``fd``.
Expand All @@ -66,7 +66,7 @@ async def wait_writable(fd: (int | _HasFileNo)) -> None:
raise RuntimeError("must be called from async context") from None


def notify_closing(fd: (int | _HasFileNo)) -> None:
def notify_closing(fd: int | _HasFileNo) -> None:
"""Notify waiters of the given object that it will be closed.

Call this before closing a file descriptor (on Unix) or socket (on
Expand Down
6 changes: 3 additions & 3 deletions src/trio/_core/_generated_io_kqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def wait_kevent(
raise RuntimeError("must be called from async context") from None


async def wait_readable(fd: (int | _HasFileNo)) -> None:
async def wait_readable(fd: int | _HasFileNo) -> None:
"""Block until the kernel reports that the given object is readable.

On Unix systems, ``fd`` must either be an integer file descriptor,
Expand Down Expand Up @@ -100,7 +100,7 @@ async def wait_readable(fd: (int | _HasFileNo)) -> None:
raise RuntimeError("must be called from async context") from None


async def wait_writable(fd: (int | _HasFileNo)) -> None:
async def wait_writable(fd: int | _HasFileNo) -> None:
"""Block until the kernel reports that the given object is writable.

See `wait_readable` for the definition of ``fd``.
Expand All @@ -119,7 +119,7 @@ async def wait_writable(fd: (int | _HasFileNo)) -> None:
raise RuntimeError("must be called from async context") from None


def notify_closing(fd: (int | _HasFileNo)) -> None:
def notify_closing(fd: int | _HasFileNo) -> None:
"""Notify waiters of the given object that it will be closed.

Call this before closing a file descriptor (on Unix) or socket (on
Expand Down
16 changes: 7 additions & 9 deletions src/trio/_core/_generated_io_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
]


async def wait_readable(sock: (_HasFileNo | int)) -> None:
async def wait_readable(sock: _HasFileNo | int) -> None:
"""Block until the kernel reports that the given object is readable.

On Unix systems, ``sock`` must either be an integer file descriptor,
Expand Down Expand Up @@ -61,7 +61,7 @@ async def wait_readable(sock: (_HasFileNo | int)) -> None:
raise RuntimeError("must be called from async context") from None


async def wait_writable(sock: (_HasFileNo | int)) -> None:
async def wait_writable(sock: _HasFileNo | int) -> None:
"""Block until the kernel reports that the given object is writable.

See `wait_readable` for the definition of ``sock``.
Expand All @@ -80,7 +80,7 @@ async def wait_writable(sock: (_HasFileNo | int)) -> None:
raise RuntimeError("must be called from async context") from None


def notify_closing(handle: (Handle | int | _HasFileNo)) -> None:
def notify_closing(handle: Handle | int | _HasFileNo) -> None:
"""Notify waiters of the given object that it will be closed.

Call this before closing a file descriptor (on Unix) or socket (on
Expand Down Expand Up @@ -112,7 +112,7 @@ def notify_closing(handle: (Handle | int | _HasFileNo)) -> None:
raise RuntimeError("must be called from async context") from None


def register_with_iocp(handle: (int | CData)) -> None:
def register_with_iocp(handle: int | CData) -> None:
"""TODO: these are implemented, but are currently more of a sketch than
anything real. See `#26
<https://github.com/python-trio/trio/issues/26>`__ and `#52
Expand All @@ -125,9 +125,7 @@ def register_with_iocp(handle: (int | CData)) -> None:
raise RuntimeError("must be called from async context") from None


async def wait_overlapped(
handle_: (int | CData), lpOverlapped: (CData | int)
) -> object:
async def wait_overlapped(handle_: int | CData, lpOverlapped: CData | int) -> object:
"""TODO: these are implemented, but are currently more of a sketch than
anything real. See `#26
<https://github.com/python-trio/trio/issues/26>`__ and `#52
Expand All @@ -143,7 +141,7 @@ async def wait_overlapped(


async def write_overlapped(
handle: (int | CData), data: Buffer, file_offset: int = 0
handle: int | CData, data: Buffer, file_offset: int = 0
) -> int:
"""TODO: these are implemented, but are currently more of a sketch than
anything real. See `#26
Expand All @@ -160,7 +158,7 @@ async def write_overlapped(


async def readinto_overlapped(
handle: (int | CData), buffer: Buffer, file_offset: int = 0
handle: int | CData, buffer: Buffer, file_offset: int = 0
) -> int:
"""TODO: these are implemented, but are currently more of a sketch than
anything real. See `#26
Expand Down
2 changes: 1 addition & 1 deletion src/trio/_core/_generated_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def spawn_system_task(
async_fn: Callable[[Unpack[PosArgT]], Awaitable[object]],
*args: Unpack[PosArgT],
name: object = None,
context: (contextvars.Context | None) = None,
context: contextvars.Context | None = None,
) -> Task:
"""Spawn a "system" task.

Expand Down
3 changes: 1 addition & 2 deletions src/trio/_core/_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@


@final
class _NoValue:
...
class _NoValue: ...


@final
Expand Down
17 changes: 7 additions & 10 deletions src/trio/_core/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,12 +830,10 @@ class TaskStatus(Protocol[StatusT_contra]):
"""

@overload
def started(self: TaskStatus[None]) -> None:
...
def started(self: TaskStatus[None]) -> None: ...

@overload
def started(self, value: StatusT_contra) -> None:
...
def started(self, value: StatusT_contra) -> None: ...

def started(self, value: StatusT_contra | None = None) -> None:
"""Tasks call this method to indicate that they have initialized.
Expand All @@ -857,12 +855,10 @@ def __repr__(self) -> str:
return f"<Task status object at {id(self):#x}>"

@overload
def started(self: _TaskStatus[None]) -> None:
...
def started(self: _TaskStatus[None]) -> None: ...

@overload
def started(self: _TaskStatus[StatusT], value: StatusT) -> None:
...
def started(self: _TaskStatus[StatusT], value: StatusT) -> None: ...

def started(self, value: StatusT | None = None) -> None:
if self._value is not _NoStatus:
Expand Down Expand Up @@ -2275,8 +2271,9 @@ def start_guest_run(
*args: object,
run_sync_soon_threadsafe: Callable[[Callable[[], object]], object],
done_callback: Callable[[outcome.Outcome[RetT]], object],
run_sync_soon_not_threadsafe: Callable[[Callable[[], object]], object]
| None = None,
run_sync_soon_not_threadsafe: (
Callable[[Callable[[], object]], object] | None
) = None,
host_uses_signal_set_wakeup_fd: bool = False,
clock: Clock | None = None,
instruments: Sequence[Instrument] = (),
Expand Down
34 changes: 13 additions & 21 deletions src/trio/_core/_tests/type_tests/nursery_start.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,44 @@
"""Test variadic generic typing for Nursery.start[_soon]()."""

from typing import Awaitable, Callable

from trio import TASK_STATUS_IGNORED, Nursery, TaskStatus


async def task_0() -> None:
...
async def task_0() -> None: ...


async def task_1a(value: int) -> None:
...
async def task_1a(value: int) -> None: ...


async def task_1b(value: str) -> None:
...
async def task_1b(value: str) -> None: ...


async def task_2a(a: int, b: str) -> None:
...
async def task_2a(a: int, b: str) -> None: ...


async def task_2b(a: str, b: int) -> None:
...
async def task_2b(a: str, b: int) -> None: ...


async def task_2c(a: str, b: int, optional: bool = False) -> None:
...
async def task_2c(a: str, b: int, optional: bool = False) -> None: ...


async def task_requires_kw(a: int, *, b: bool) -> None:
...
async def task_requires_kw(a: int, *, b: bool) -> None: ...


async def task_startable_1(
a: str,
*,
task_status: TaskStatus[bool] = TASK_STATUS_IGNORED,
) -> None:
...
) -> None: ...


async def task_startable_2(
a: str,
b: float,
*,
task_status: TaskStatus[bool] = TASK_STATUS_IGNORED,
) -> None:
...
) -> None: ...


async def task_requires_start(*, task_status: TaskStatus[str]) -> None:
Expand Down Expand Up @@ -75,9 +67,9 @@ def check_start_soon(nursery: Nursery) -> None:
nursery.start_soon(task_2c, "abc", 12, True)

nursery.start_soon(task_2c, "abc", 12)
task_2c_cast: Callable[
[str, int], Awaitable[object]
] = task_2c # The assignment makes it work.
task_2c_cast: Callable[[str, int], Awaitable[object]] = (
task_2c # The assignment makes it work.
)
nursery.start_soon(task_2c_cast, "abc", 12)

nursery.start_soon(task_requires_kw, 12, True) # type: ignore
Expand Down
13 changes: 8 additions & 5 deletions src/trio/_core/_thread_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,14 @@ def darwin_namefunc(

class WorkerThread(Generic[RetT]):
def __init__(self, thread_cache: ThreadCache) -> None:
self._job: tuple[
Callable[[], RetT],
Callable[[outcome.Outcome[RetT]], object],
str | None,
] | None = None
self._job: (
tuple[
Callable[[], RetT],
Callable[[outcome.Outcome[RetT]], object],
str | None,
]
| None
) = None
self._thread_cache = thread_cache
# This Lock is used in an unconventional way.
#
Expand Down
1 change: 1 addition & 0 deletions src/trio/_core/_traps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""These are the only functions that ever yield back to the task runner."""

from __future__ import annotations

import enum
Expand Down
Loading
Loading