Skip to content

Commit

Permalink
Merge pull request #24 from mikenerone/mikenerone/typed-trio
Browse files Browse the repository at this point in the history
Trio is now typed, no need for trio-typing
  • Loading branch information
oremanj authored Jan 11, 2024
2 parents d9226be + 4ea9df8 commit 2736e5b
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 74 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ['3.7', '3.8', '3.9', '3.10', '3.11']
python: ['3.8', '3.9', '3.10', '3.11', '3.12']
arch: ['x86', 'x64']
steps:
- name: Checkout
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ['pypy-3.8', 'pypy-3.9', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12-dev']
python: ['pypy-3.8', 'pypy-3.9', '3.8', '3.9', '3.10', '3.11', '3.12']
check_lint: ['0']
extra_name: ['']
include:
Expand Down Expand Up @@ -103,7 +103,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ['3.7', '3.8', '3.9', '3.10', '3.11']
python: ['3.8', '3.9', '3.10', '3.11', '3.12']
include:
- python: '3.8' # <- not actually used
arch: 'x64'
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ cleanliness and good test coverage, please be advised that
good idea at the time, and should be treated with according skepticism
if you're contemplating using it in production. It hasn't necessarily
been reviewed or tested to Trio's standards, it supports at minimum
Python 3.7, and some features might not be available on PyPy or on
Python 3.8, and some features might not be available on PyPy or on
Windows.

* If you find that it meets your needs, you're welcome to use it. We'll
Expand Down
3 changes: 1 addition & 2 deletions docs-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ sphinx >= 1.7.0
sphinx_rtd_theme
sphinxcontrib-trio
towncrier
trio >= 0.15.0
trio-typing >= 0.5.0
trio >= 0.23.0
23 changes: 2 additions & 21 deletions docs-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile docs-requirements.in
#

alabaster==0.7.13
# via sphinx
async-generator==1.10
# via trio
attrs==23.1.0
# via
# outcome
Expand All @@ -29,16 +26,12 @@ docutils==0.18.1
# via
# sphinx
# sphinx-rtd-theme
exceptiongroup==1.1.1
# via trio
idna==3.4
# via
# requests
# trio
imagesize==1.4.1
# via sphinx
importlib-metadata==6.6.0
# via sphinx
incremental==22.10.0
# via towncrier
jinja2==3.1.2
Expand All @@ -47,8 +40,6 @@ jinja2==3.1.2
# towncrier
markupsafe==2.1.3
# via jinja2
mypy-extensions==1.0.0
# via trio-typing
outcome==1.2.0
# via trio
packaging==23.1
Expand Down Expand Up @@ -87,22 +78,12 @@ sphinxcontrib-serializinghtml==1.1.5
# via sphinx
sphinxcontrib-trio==1.1.2
# via -r docs-requirements.in
tomli==2.0.1
# via towncrier
towncrier==22.12.0
# via -r docs-requirements.in
trio==0.22.0
# via
# -r docs-requirements.in
# trio-typing
trio-typing==0.8.0
trio==0.24.0
# via -r docs-requirements.in
typing-extensions==4.6.3
# via trio-typing
urllib3==2.0.2
# via requests
zipp==3.15.0
# via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
# setuptools
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.black]
target-version = ['py37']
target-version = ['py38']

[tool.towncrier]
package = "tricycle"
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
license="MIT -or- Apache License 2.0",
packages=find_packages(),
include_package_data=True,
install_requires=["trio >= 0.15.0", "trio-typing >= 0.5.0"],
install_requires=["trio >= 0.23.0"],
keywords=["async", "trio"],
python_requires=">=3.7",
python_requires=">=3.8",
classifiers=[
"License :: OSI Approved :: MIT License",
"License :: OSI Approved :: Apache Software License",
Expand Down
5 changes: 2 additions & 3 deletions test-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ pytest-trio >= 0.6.0

# Tools
black; implementation_name == "cpython"
mypy >= 0.780; implementation_name == "cpython"
mypy >= 1.8.0; implementation_name == "cpython"
# 6.0.0 requires py3.8+:
flake8 < 6.0.0

# Project dependencies
attrs >= 19.2.0
async_generator >= 1.9
trio >= 0.15.0
trio-typing >= 0.5.0
trio >= 0.23.0
32 changes: 8 additions & 24 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile test-requirements.in
#

async-generator==1.10
# via
# -r test-requirements.in
# trio
# via -r test-requirements.in
attrs==23.1.0
# via
# -r test-requirements.in
# outcome
# trio
black==23.3.0 ; implementation_name == "cpython"
# via -r test-requirements.in
click==8.1.3
# via black
coverage[toml]==7.2.7
# via pytest-cov
exceptiongroup==1.1.1
# via
# pytest
# trio
# coverage
# pytest-cov
flake8==5.0.4
# via -r test-requirements.in
idna==3.4
Expand All @@ -31,13 +27,12 @@ iniconfig==2.0.0
# via pytest
mccabe==0.7.0
# via flake8
mypy==1.3.0 ; implementation_name == "cpython"
mypy==1.8.0 ; implementation_name == "cpython"
# via -r test-requirements.in
mypy-extensions==1.0.0
# via
# black
# mypy
# trio-typing
outcome==1.2.0
# via
# pytest-trio
Expand Down Expand Up @@ -69,20 +64,9 @@ sniffio==1.3.0
# via trio
sortedcontainers==2.4.0
# via trio
tomli==2.0.1
# via
# black
# mypy
# pytest
trio==0.22.0
trio==0.24.0
# via
# -r test-requirements.in
# pytest-trio
# trio-typing
trio-typing==0.8.0
# via -r test-requirements.in
typing-extensions==4.6.3
# via
# black
# mypy
# trio-typing
# via mypy
6 changes: 2 additions & 4 deletions tricycle/_service_nursery.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import attr
import collections
import trio
from trio_typing import TaskStatus
from functools import partial
from contextlib import asynccontextmanager
from typing import Any, AsyncIterator, Awaitable, Callable, Optional, overload
from typing import Any, AsyncIterator, Awaitable, Callable, Optional
from ._multi_cancel import MultiCancelScope


Expand Down Expand Up @@ -112,7 +110,7 @@ async def start(
*args: Any,
name: Optional[str] = None,
) -> Any:
async def wrap_child(*, task_status: TaskStatus[Any]) -> None:
async def wrap_child(*, task_status: trio.TaskStatus[Any]) -> None:
# For start(), the child doesn't get shielded until it
# calls task_status.started().
shield_scope = child_task_scopes.open_child(shield=False)
Expand Down
5 changes: 2 additions & 3 deletions tricycle/_tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import trio
import trio.testing
from contextlib import asynccontextmanager
from typing import Any, AsyncIterator, Coroutine, Iterator, List
from trio_typing import TaskStatus
from typing import AsyncIterator, Coroutine, Iterator, List

from .. import ScopedObject, BackgroundObject

Expand Down Expand Up @@ -109,7 +108,7 @@ async def __close__(self) -> None:
self.record.append("close")
self.exiting = True

async def _background_task(self, *, task_status: TaskStatus[None]) -> None:
async def _background_task(self, *, task_status: trio.TaskStatus[None]) -> None:
self.record.append("background")
await trio.sleep(1)
self.record.append("starting")
Expand Down
5 changes: 2 additions & 3 deletions tricycle/_tests/test_rwlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import trio.testing
from .. import RWLock
from typing import List, Optional
from trio_typing import TaskStatus


async def test_rwlock(autojump_clock: trio.testing.MockClock) -> None:
Expand Down Expand Up @@ -41,7 +40,7 @@ async def test_rwlock(autojump_clock: trio.testing.MockClock) -> None:
acquire_times: List[Optional[float]] = [None] * 10

async def holder_task(
for_write: bool, task_status: TaskStatus[trio.lowlevel.Task]
for_write: bool, task_status: trio.TaskStatus[trio.lowlevel.Task]
) -> None:
my_slot = next(start_order)
repr(lock) # smoke test
Expand Down Expand Up @@ -150,7 +149,7 @@ async def test_read_biased(autojump_clock: trio.testing.MockClock) -> None:
assert lock.read_biased

async def holder_task(
for_write: bool, task_status: TaskStatus[trio.lowlevel.Task]
for_write: bool, task_status: trio.TaskStatus[trio.lowlevel.Task]
) -> None:
task_status.started(trio.lowlevel.current_task())
await lock.acquire(for_write=for_write)
Expand Down
7 changes: 3 additions & 4 deletions tricycle/_tests/test_service_nursery.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
from typing import Any
from trio_typing import TaskStatus

import trio
import trio.testing
Expand Down Expand Up @@ -35,7 +34,7 @@ async def background_task() -> None:
async def test_start(autojump_clock: trio.testing.MockClock) -> None:
record = []

async def sleep_then_start(val: int, *, task_status: TaskStatus[int]) -> None:
async def sleep_then_start(val: int, *, task_status: trio.TaskStatus[int]) -> None:
await trio.sleep(1)
task_status.started(val)
try:
Expand All @@ -44,7 +43,7 @@ async def sleep_then_start(val: int, *, task_status: TaskStatus[int]) -> None:
finally:
record.append("background task exiting")

async def shielded_sleep_then_start(*, task_status: TaskStatus[None]) -> None:
async def shielded_sleep_then_start(*, task_status: trio.TaskStatus[None]) -> None:
with trio.CancelScope(shield=True):
await trio.sleep(1)
task_status.started()
Expand Down Expand Up @@ -83,7 +82,7 @@ async def shielded_sleep_then_start(*, task_status: TaskStatus[None]) -> None:
async def test_problems() -> None:
async with open_service_nursery() as nursery:
with pytest.raises(TypeError) as info:
nursery.start_soon(trio.sleep)
nursery.start_soon(trio.sleep) # type: ignore[arg-type]
assert "missing 1 required positional argument" in str(info.value)

with pytest.raises(TypeError) as info:
Expand Down
5 changes: 2 additions & 3 deletions tricycle/_tests/test_tree_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import trio
import trio.testing
from functools import partial
from trio_typing import TaskStatus
from typing import Optional, Any, cast

from .. import TreeVar, TreeVarToken
Expand Down Expand Up @@ -69,7 +68,7 @@ def trivial_abort(_: object) -> trio.lowlevel.Abort:
async def test_treevar_follows_eventual_parent() -> None:
tv1 = TreeVar[str]("tv1")

async def manage_target(task_status: TaskStatus[trio.Nursery]) -> None:
async def manage_target(task_status: trio.TaskStatus[trio.Nursery]) -> None:
assert tv1.get() == "source nursery"
with tv1.being("target nursery"):
assert tv1.get() == "target nursery"
Expand All @@ -84,7 +83,7 @@ async def manage_target(task_status: TaskStatus[trio.Nursery]) -> None:
assert tv1.get() == "source nursery"

async def verify(
value: str, *, task_status: TaskStatus[None] = trio.TASK_STATUS_IGNORED
value: str, *, task_status: trio.TaskStatus[None] = trio.TASK_STATUS_IGNORED
) -> None:
assert tv1.get() == value
task_status.started()
Expand Down

0 comments on commit 2736e5b

Please sign in to comment.