Skip to content

Commit

Permalink
CI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
oremanj committed Dec 1, 2023
1 parent fc7eeb8 commit 8db07b5
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Install trio-typing with mypy extras::

pip install trio-typing[mypy]

Note that due to recent plugin API changes, trio-typing 0.7.0+ requires mypy 0.920+.
Note that due to recent plugin API changes, trio-typing 0.10.0+ requires mypy 1.0+.

Enable the plugin in your ``mypy.ini``::

Expand Down
2 changes: 2 additions & 0 deletions allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ trio.Process.__aenter__
.*_AttrsAttributes__
.*__attrs_own_setattr__
.*__attrs_post_init__
.*_AT
.*__slots__

# Probably invalid __match_args__
trio.MemoryReceiveChannel.__match_args__
Expand Down
2 changes: 1 addition & 1 deletion ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -ex -o pipefail

BLACK_VERSION=22.3
MYPY_VERSION=1.4
MYPY_VERSION=1.7

pip install -U pip setuptools wheel

Expand Down
8 changes: 4 additions & 4 deletions trio-stubs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class Event(metaclass=ABCMeta):
class CapacityLimiterStatistics:
borrowed_tokens: int = attr.ib()
total_tokens: int | float = attr.ib()
borrowers: list[Task | object] = attr.ib()
borrowers: list[trio.lowlevel.Task | object] = attr.ib()
tasks_waiting: int = attr.ib()

@final
Expand Down Expand Up @@ -271,7 +271,7 @@ class Semaphore(metaclass=ABCMeta):
@attr.s(frozen=True, slots=True)
class LockStatistics:
locked: bool = attr.ib()
owner: Task | None = attr.ib()
owner: trio.lowlevel.Task | None = attr.ib()
tasks_waiting: int = attr.ib()

@final
Expand Down Expand Up @@ -375,7 +375,7 @@ class MemoryReceiveChannel(trio.abc.ReceiveChannel[_T_co]):
async def receive(self) -> _T_co: ...
def clone(self: _T) -> _T: ...
async def aclose(self) -> None: ...
def statistics(self) -> _Statistics: ...
def statistics(self) -> _MemoryChannelStats: ...
def close(self) -> None: ...
def __enter__(self) -> MemoryReceiveChannel[_T_co]: ...
def __exit__(
Expand Down Expand Up @@ -403,7 +403,7 @@ class SocketStream(trio.abc.HalfCloseableStream):
socket: trio.socket.SocketType
def __init__(self, socket: trio.socket.SocketType) -> None: ...
@overload
def setsockopt(self, level: int, option: int, value: int | Buffer) -> None: ...
def setsockopt(self, level: int, option: int, value: int | Buffer, length: None = None) -> None: ...
@overload
def setsockopt(self, level: int, option: int, value: None, length: int) -> None: ...
@overload
Expand Down
9 changes: 8 additions & 1 deletion trio-stubs/abc.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import socket
import trio
from abc import ABCMeta, abstractmethod
from typing import List, Tuple, Union, Any, Optional, Generic, TypeVar, AsyncIterator
from types import TracebackType

_T = TypeVar("_T")

Expand Down Expand Up @@ -52,7 +54,12 @@ class AsyncResource(metaclass=ABCMeta):
@abstractmethod
async def aclose(self) -> None: ...
async def __aenter__(self: _T) -> _T: ...
async def __aexit__(self, *exc: object) -> None: ...
async def __aexit__(
self,
exc_type: type[BaseException] | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
) -> None: ...

class SendStream(AsyncResource):
@abstractmethod
Expand Down
17 changes: 10 additions & 7 deletions trio-stubs/lowlevel.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class UnboundedQueue(Generic[_T], metaclass=ABCMeta):
# _core._run
if sys.platform == "win32":
@attr.frozen
class IOStatistics:
class _IOStatistics:
tasks_waiting_read: int = attr.ib()
tasks_waiting_write: int = attr.ib()
tasks_waiting_overlapped: int = attr.ib()
Expand All @@ -84,14 +84,14 @@ if sys.platform == "win32":

elif sys.platform == "linux":
@attr.frozen
class IOStatistics:
class _IOStatistics:
tasks_waiting_read: int = attr.ib()
tasks_waiting_write: int = attr.ib()
backend: Literal["epoll"] = attr.ib(init=False, default="epoll")

else: # kqueue
@attr.frozen
class IOStatistics:
class _IOStatistics:
tasks_waiting: int = attr.ib()
monitors: int = attr.ib()
backend: Literal["kqueue"] = attr.ib(init=False, default="kqueue")
Expand All @@ -101,7 +101,7 @@ class RunStatistics:
tasks_living: int
tasks_runnable: int
seconds_to_next_deadline: float
io_statistics: IOStatistics
io_statistics: _IOStatistics
run_sync_soon_queue_size: int

@final
Expand Down Expand Up @@ -213,9 +213,12 @@ class ParkingLot(metaclass=ABCMeta):
# _core._local
class _NoValue: ...

class RunVarToken(Generic[_T]):
previous_value: T | type[_NoValue]
redeemed: bool
@final
@attr.s(eq=False, hash=False, slots=True)
class RunVarToken(Generic[_T], metaclass=ABCMeta):
_var: RunVar[_T] = attr.ib()
previous_value: _T | type[_NoValue] = attr.ib(default=_NoValue)
redeemed: bool = attr.ib(init=False)

@final
@attr.s(eq=False, hash=False, slots=True)
Expand Down
2 changes: 1 addition & 1 deletion trio_typing/_tests/test-data/async_generator.test
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def dummy():

firstiter = agen.get_asyncgen_hooks().firstiter
if firstiter is not None:
firstiter(iter([])) # E: Argument 1 has incompatible type "Iterator[<nothing>]"; expected "AsyncGenerator[Any, Any]"
firstiter(iter([])) # E: Argument 1 has incompatible type "Iterator[Never]"; expected "AsyncGenerator[Any, Any]"
reveal_type(firstiter(dummy())) # N: Revealed type is "Any"
agen.set_asyncgen_hooks(firstiter)
agen.set_asyncgen_hooks(firstiter, finalizer=firstiter)
Expand Down
2 changes: 1 addition & 1 deletion trio_typing/_tests/test-data/outcome.test
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ async def test() -> None:
reveal_type(test_outcome.unwrap()) # N: Revealed type is "builtins.str"
reveal_type(test_outcome.send(calc_lengths())) # N: Revealed type is "builtins.int"
reveal_type(await test_outcome.asend(calc_lengths_async())) # N: Revealed type is "builtins.int"
test_outcome.send(wrong_type_gen()) # E: Argument 1 to "send" of "Value" has incompatible type "Iterator[int]"; expected "Generator[<nothing>, str, Any]" # E: Argument 1 to "send" of "Error" has incompatible type "Iterator[int]"; expected "Generator[<nothing>, Any, Any]"
test_outcome.send(wrong_type_gen()) # E: Argument 1 to "send" of "Value" has incompatible type "Iterator[int]"; expected "Generator[Never, str, Any]" # E: Argument 1 to "send" of "Error" has incompatible type "Iterator[int]"; expected "Generator[Never, Any, Any]"
6 changes: 3 additions & 3 deletions trio_typing/_tests/test-data/taskstatus.test
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ async def parent() -> None:
nursery.start_soon(child2) # E: Argument 1 to "start_soon" of "Nursery" has incompatible type "Callable[[int, DefaultNamedArg(TaskStatus[None], 'task_status')], Coroutine[Any, Any, None]]"; expected "Callable[[], Awaitable[Any]]"
nursery.start_soon(child2, "hi") # E: Argument 1 to "start_soon" of "Nursery" has incompatible type "Callable[[int, DefaultNamedArg(TaskStatus[None], 'task_status')], Coroutine[Any, Any, None]]"; expected "Callable[[str], Awaitable[Any]]"
nursery.start_soon(child2, 50)
await nursery.start(child) # E: Argument 1 to "start" of "Nursery" has incompatible type "Callable[[int, NamedArg(TaskStatus[int], 'task_status')], Coroutine[Any, Any, None]]"; expected "Callable[[NamedArg(TaskStatus[<nothing>], 'task_status')], Awaitable[Any]]"
await nursery.start(child) # E: Argument 1 to "start" of "Nursery" has incompatible type "Callable[[int, NamedArg(TaskStatus[int], 'task_status')], Coroutine[Any, Any, None]]"; expected "Callable[[NamedArg(TaskStatus[int], 'task_status')], Awaitable[Any]]"
await nursery.start(child, "hi") # E: Argument 1 to "start" of "Nursery" has incompatible type "Callable[[int, NamedArg(TaskStatus[int], 'task_status')], Coroutine[Any, Any, None]]"; expected "Callable[[str, NamedArg(TaskStatus[int], 'task_status')], Awaitable[Any]]"
result = await nursery.start(child, 10)
result2 = await nursery.start(child2, 10) # E: Function does not return a value
result2 = await nursery.start(child2, 10) # E: Function does not return a value (it only ever returns None)
await nursery.start(child2, 10)
reveal_type(result) # N: Revealed type is "builtins.int"

Expand Down Expand Up @@ -54,6 +54,6 @@ async def parent() -> None:
await nursery.start(child)
await nursery.start(child, "hi")
result = await nursery.start(child, 10)
result2 = await nursery.start(child2, 10) # E: Function does not return a value
result2 = await nursery.start(child2, 10) # E: Function does not return a value (it only ever returns None)
await nursery.start(child2, 10)
reveal_type(result) # N: Revealed type is "builtins.int"
9 changes: 2 additions & 7 deletions trio_typing/_tests/test-data/trio-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ reveal_type(val) # N: Revealed type is "builtins.list[builtins.float]"
trio.run(sleep_sort, ["hi", "there"]) # E: Argument 1 to "run" has incompatible type "Callable[[Sequence[float]], Coroutine[Any, Any, List[float]]]"; expected "Callable[[List[str]], Awaitable[List[float]]]"


reveal_type(trio.Event().statistics().anything) # N: Revealed type is "Any"
reveal_type(trio.Event().statistics().tasks_waiting) # N: Revealed type is "builtins.int"

[case testTrioBasic_NoPlugin]
import trio
Expand Down Expand Up @@ -55,7 +55,7 @@ val = trio.run(sleep_sort, (1, 3, 5, 2, 4), clock=trio.testing.MockClock(autojum
reveal_type(val) # N: Revealed type is "builtins.list[builtins.float]"
trio.run(sleep_sort, ["hi", "there"])

reveal_type(trio.Event().statistics().anything) # N: Revealed type is "Any"
reveal_type(trio.Event().statistics().tasks_waiting) # N: Revealed type is "builtins.int"

[case testExceptions]
import trio
Expand All @@ -75,11 +75,6 @@ def filter_exc(exc: BaseException):
with trio.MultiError.catch(filter_exc):
pass

try:
trio.run(trio.sleep, 3)
except trio.MultiError as ex:
reveal_type(ex.exceptions[0]) # N: Revealed type is "builtins.BaseException"

[case testOverloaded]
from typing import overload, Any

Expand Down

0 comments on commit 8db07b5

Please sign in to comment.