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 15 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
12 changes: 12 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import re
import sys

# For our local_customization module
Expand Down Expand Up @@ -108,6 +109,17 @@ def autodoc_process_signature(
# Strip the type from the union, make it look like = ...
signature = signature.replace(" | type[trio._core._local._NoValue]", "")
signature = signature.replace("<class 'trio._core._local._NoValue'>", "...")
if name.startswith("trio.testing"):
# Expand type aliases
signature = re.sub(
r"StreamMaker\[([a-zA-Z ,]+)]",
lambda match: f"typing.Callable[[], typing.Awaitable[tuple[{match.group(1)}]]]",
signature,
)
signature = signature.replace(
"AsyncHook", "typing.Callable[[], typing.Awaitable[object]]"
)
signature = signature.replace("SyncHook", "typing.Callable[[], object]")

return signature, return_annotation

Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ module = [
"trio._sync",
"trio._tools.gen_exports",
"trio._util",
"trio.testing",
"trio.testing._check_streams",
"trio.testing._checkpoints",
"trio.testing._memory_streams",
"trio.testing._network",
"trio.testing._sequencer",
"trio.testing._trio_test",
TeamSpen210 marked this conversation as resolved.
Show resolved Hide resolved
]
disallow_incomplete_defs = true
disallow_untyped_defs = true
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
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.9490445859872612,
"completenessScore": 0.9713375796178344,
"exportedSymbolCounts": {
"withAmbiguousType": 0,
"withKnownType": 596,
"withUnknownType": 32
"withKnownType": 610,
"withUnknownType": 18
},
"ignoreUnknownTypesFromImports": true,
"missingClassDocStringCount": 1,
"missingDefaultParamCount": 0,
"missingFunctionDocStringCount": 4,
"missingFunctionDocStringCount": 3,
"moduleName": "trio",
"modules": [
{
Expand Down Expand Up @@ -46,8 +46,8 @@
],
"otherSymbolCounts": {
"withAmbiguousType": 3,
"withKnownType": 627,
"withUnknownType": 50
"withKnownType": 647,
"withUnknownType": 30
},
"packageName": "trio",
"symbols": [
Expand Down Expand Up @@ -96,36 +96,6 @@
"trio.run_process",
"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",
"trio.to_thread.current_default_thread_limiter"
]
Expand Down
Loading