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

Add types to most of trio.testing #2747

Merged
merged 23 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b75487f
Add types to trio.testing._trio_test
TeamSpen210 Aug 8, 2023
391f42b
Add types to trio.testing._check_streams
TeamSpen210 Aug 8, 2023
e3cb71e
Add types to trio.testing._checkpoints
TeamSpen210 Aug 8, 2023
737b8e2
Add types to trio.testing._network
TeamSpen210 Aug 8, 2023
e1e5aa3
Add types to trio.testing._memory_streams
TeamSpen210 Aug 8, 2023
fcd6831
Enable strict tests for most of trio.testing, fill in some missing ones
TeamSpen210 Aug 8, 2023
11ce4ff
Run linters
TeamSpen210 Aug 8, 2023
073cae1
Update verify_types.json
TeamSpen210 Aug 8, 2023
68eaad7
Introduce some type aliases to make code more readable
TeamSpen210 Aug 9, 2023
3c6b14c
Accept bytearray/memoryview in functions where applicable
TeamSpen210 Aug 9, 2023
c1fcd4a
Expand the type aliases in trio.testing for docs
TeamSpen210 Aug 9, 2023
e1e5596
Merge branch 'master' into type-testing
TeamSpen210 Aug 10, 2023
2fd7ae4
Merge remote-tracking branch 'origin/master' into type-testing
jakkdl Aug 14, 2023
d1a2c99
fix return type of trio/_core/_run to not be an awaitable, remove typ…
jakkdl Aug 14, 2023
9538fd5
Merge remote-tracking branch 'origin/master' into type-testing
jakkdl Aug 14, 2023
e8fbc12
Un-stringify these aliases
TeamSpen210 Aug 15, 2023
7877591
Make StapledStream generic, to preserve the type of the component str…
TeamSpen210 Aug 16, 2023
2b669c7
add _highlevel_generic to mypy strictlist
jakkdl Aug 17, 2023
fa72c50
Merge remote-tracking branch 'origin/master' into type-testing
jakkdl Aug 17, 2023
d191c39
fix missing generic parameter
jakkdl Aug 17, 2023
ad41571
fix CI
jakkdl Aug 17, 2023
6a9ad46
Merge branch 'master' into type-testing
TeamSpen210 Aug 18, 2023
054fe70
Update pyproject.toml
jakkdl Aug 18, 2023
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
7 changes: 0 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ disallow_untyped_calls = false
# files not yet fully typed
[[tool.mypy.overrides]]
module = [
# 2747
"trio/testing/_network",
"trio/testing/_trio_test",
"trio/testing/_checkpoints",
"trio/testing/_check_streams",
"trio/testing/_memory_streams",
# 2745
"trio/_ssl",
# 2756
Expand All @@ -70,7 +64,6 @@ module = [
"trio/_core/_generated_io_windows",
"trio/_core/_io_windows",


"trio/_signals",

# internal
Expand Down
2 changes: 1 addition & 1 deletion trio/_core/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2152,7 +2152,7 @@ def setup_runner(


def run(
async_fn: Callable[..., RetT],
async_fn: Callable[..., Awaitable[RetT]],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Geh. I assume there's no other things like this?

*args: object,
clock: Clock | None = None,
instruments: Sequence[Instrument] = (),
Expand Down
18 changes: 11 additions & 7 deletions trio/_highlevel_generic.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import Generic, TypeVar

import attr

import trio
from trio._util import Final

if TYPE_CHECKING:
from .abc import SendStream, ReceiveStream, AsyncResource
from .abc import AsyncResource, HalfCloseableStream, ReceiveStream, SendStream

from .abc import HalfCloseableStream
SendStreamT = TypeVar("SendStreamT", bound=SendStream)
ReceiveStreamT = TypeVar("ReceiveStreamT", bound=ReceiveStream)


async def aclose_forcefully(resource: AsyncResource) -> None:
Expand Down Expand Up @@ -44,7 +44,11 @@ async def aclose_forcefully(resource: AsyncResource) -> None:


@attr.s(eq=False, hash=False)
class StapledStream(HalfCloseableStream, metaclass=Final):
class StapledStream(
HalfCloseableStream,
Generic[SendStreamT, ReceiveStreamT],
metaclass=Final,
):
"""This class `staples <https://en.wikipedia.org/wiki/Staple_(fastener)>`__
together two unidirectional streams to make single bidirectional stream.

Expand Down Expand Up @@ -79,8 +83,8 @@ class StapledStream(HalfCloseableStream, metaclass=Final):

"""

send_stream: SendStream = attr.ib()
receive_stream: ReceiveStream = attr.ib()
send_stream: SendStreamT = attr.ib()
receive_stream: ReceiveStreamT = attr.ib()

async def send_all(self, data: bytes | bytearray | memoryview) -> None:
"""Calls ``self.send_stream.send_all``."""
Expand Down
2 changes: 1 addition & 1 deletion trio/_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def __init__(
self.stdout = stdout
self.stderr = stderr

self.stdio: StapledStream | None = None
self.stdio: StapledStream[SendStream, ReceiveStream] | None = None
if self.stdin is not None and self.stdout is not None:
self.stdio = StapledStream(self.stdin, self.stdout)

Expand Down
42 changes: 6 additions & 36 deletions trio/_tests/verify_types.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
"warningCount": 0
},
"typeCompleteness": {
"completenessScore": 0.964968152866242,
"completenessScore": 0.9872611464968153,
"exportedSymbolCounts": {
"withAmbiguousType": 0,
"withKnownType": 606,
"withUnknownType": 22
"withKnownType": 620,
"withUnknownType": 8
},
"ignoreUnknownTypesFromImports": true,
"missingClassDocStringCount": 1,
"missingDefaultParamCount": 0,
"missingFunctionDocStringCount": 4,
"missingFunctionDocStringCount": 3,
"moduleName": "trio",
"modules": [
{
Expand Down Expand Up @@ -46,8 +46,8 @@
],
"otherSymbolCounts": {
"withAmbiguousType": 1,
"withKnownType": 642,
"withUnknownType": 39
"withKnownType": 662,
"withUnknownType": 19
},
"packageName": "trio",
"symbols": [
Expand Down Expand Up @@ -76,36 +76,6 @@
"trio.open_unix_socket",
"trio.serve_listeners",
"trio.serve_ssl_over_tcp",
"trio.testing._memory_streams.MemoryReceiveStream.__init__",
"trio.testing._memory_streams.MemoryReceiveStream.aclose",
"trio.testing._memory_streams.MemoryReceiveStream.close",
"trio.testing._memory_streams.MemoryReceiveStream.close_hook",
"trio.testing._memory_streams.MemoryReceiveStream.put_data",
"trio.testing._memory_streams.MemoryReceiveStream.put_eof",
"trio.testing._memory_streams.MemoryReceiveStream.receive_some",
"trio.testing._memory_streams.MemoryReceiveStream.receive_some_hook",
"trio.testing._memory_streams.MemorySendStream.__init__",
"trio.testing._memory_streams.MemorySendStream.aclose",
"trio.testing._memory_streams.MemorySendStream.close",
"trio.testing._memory_streams.MemorySendStream.close_hook",
"trio.testing._memory_streams.MemorySendStream.get_data",
"trio.testing._memory_streams.MemorySendStream.get_data_nowait",
"trio.testing._memory_streams.MemorySendStream.send_all",
"trio.testing._memory_streams.MemorySendStream.send_all_hook",
"trio.testing._memory_streams.MemorySendStream.wait_send_all_might_not_block",
"trio.testing._memory_streams.MemorySendStream.wait_send_all_might_not_block_hook",
"trio.testing.assert_checkpoints",
"trio.testing.assert_no_checkpoints",
"trio.testing.check_half_closeable_stream",
"trio.testing.check_one_way_stream",
"trio.testing.check_two_way_stream",
"trio.testing.lockstep_stream_one_way_pair",
"trio.testing.lockstep_stream_pair",
"trio.testing.memory_stream_one_way_pair",
"trio.testing.memory_stream_pair",
"trio.testing.memory_stream_pump",
"trio.testing.open_stream_to_socket_listener",
"trio.testing.trio_test",
"trio.tests.TestsDeprecationWrapper"
]
}
Expand Down
Loading