Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
8dfdd56
various small type fixes, disallow_incomplete_defs = true, except for…
jakkdl Jul 11, 2023
46ac4e8
stuff
jakkdl Jul 12, 2023
4678d44
typecheck trio/_dtls.py
jakkdl Jul 13, 2023
2522bc5
incorporate _abc
jakkdl Jul 13, 2023
909ac67
incorporate _dtls
jakkdl Jul 13, 2023
40ff89f
ignore weird error with TASK_STATUS_IGNORED, add pyOpenSSL to docs-re…
jakkdl Jul 13, 2023
f18abdd
socket is done - other than getting rid of the _SocketType <-> Socket…
jakkdl Jul 14, 2023
07fcdf0
Merge remote-tracking branch 'origin/master' into typing_improvements…
jakkdl Jul 20, 2023
128a8d2
fix RTD, and export DTLSChannelStatistics and TaskStatus
jakkdl Jul 20, 2023
0e9aedd
update .gitattributes
jakkdl Jul 21, 2023
f08e848
Merge remote-tracking branch 'origin/master' into typing_improvements…
jakkdl Jul 21, 2023
c5b43a0
fixes after review from ZacHD
jakkdl Jul 21, 2023
9e3feb8
Merge remote-tracking branch 'origin/master' into typing_improvements…
jakkdl Jul 23, 2023
58e4412
fixes after review by a5rocks
jakkdl Jul 23, 2023
eda238b
oopsies
jakkdl Jul 23, 2023
60f06f1
Merge remote-tracking branch 'origin/master' into typing_improvements_2
jakkdl Jul 23, 2023
c437821
aoeu
jakkdl Jul 23, 2023
0fbb87f
merge _dtls
jakkdl Jul 23, 2023
528f83c
Merge branch 'typing_improvements_dtls' into typing_improvements_2
jakkdl Jul 23, 2023
3d92de4
merge-ish _socket
jakkdl Jul 23, 2023
2a51953
_sync
jakkdl Jul 23, 2023
4b513bd
type _io_epoll and stuff
jakkdl Jul 24, 2023
1831eae
aborted -> abort
jakkdl Jul 26, 2023
091063b
merge _socket, more stuff
jakkdl Jul 24, 2023
46d9e95
regen
jakkdl Jul 24, 2023
156c94f
progress
jakkdl Jul 24, 2023
12b5af7
mypy can now be run on trio/
jakkdl Jul 25, 2023
2490873
started playing around with windows but mostly gave up. Some types ad…
jakkdl Jul 25, 2023
a349d99
_core/_thread_cache
jakkdl Jul 25, 2023
7ed3a7b
type _traps as far as it's possible ... but tests are failing
jakkdl Jul 25, 2023
1974a5c
fix after nit from a5
jakkdl Jul 26, 2023
d0fae93
fix test errors
jakkdl Jul 26, 2023
e562a85
Merge remote-tracking branch 'origin/master' into typing_improvements_2
jakkdl Jul 26, 2023
f353058
_asyncgens
jakkdl Jul 26, 2023
766efdc
_wakeup_socketpair
jakkdl Jul 26, 2023
6a13de7
trio/_core/_ki
jakkdl Jul 26, 2023
420e98b
trio/_core/_entry_queue
jakkdl Jul 26, 2023
2370c3f
type trio/_core/_run
jakkdl Jul 27, 2023
ae32ea9
typecheck trio/_core/_unbounded_queue
jakkdl Jul 28, 2023
ea19988
fix CI
jakkdl Jul 28, 2023
b4621e5
fix test
jakkdl Jul 28, 2023
d251196
fix Statistics not defining slots breaking tests
jakkdl Jul 28, 2023
34341c2
Any -> object in _entry_queue
jakkdl Jul 28, 2023
e08d79c
merge and playing around with io
jakkdl Jul 28, 2023
cf20b63
adding py.typed, for the fun of it
jakkdl Jul 28, 2023
ddc771b
Merge remote-tracking branch 'origin/master' into typing_improvements_
jakkdl Jul 29, 2023
69a1db3
Merge remote-tracking branch 'origin/master' into typing_improvements_
jakkdl Aug 1, 2023
6b724c6
Merge remote-tracking branch 'origin/master' into typing_improvements_
jakkdl Aug 1, 2023
dc8c18c
.
jakkdl Aug 6, 2023
ffb4c17
Merge remote-tracking branch 'origin/master' into typing_improvements_
jakkdl Aug 6, 2023
db90a85
Merge remote-tracking branch 'origin/master' into typing_improvements_
jakkdl Aug 10, 2023
9bde0a1
reset _core/_run in expectation of #2733
jakkdl Aug 10, 2023
048b48a
rearrange files in toml
jakkdl Aug 10, 2023
e47517f
Merge remote-tracking branch 'origin/master' into typing_improvements_
jakkdl Aug 10, 2023
5c0a25c
remove unnecessary/incorrect diffs relative to master
jakkdl Aug 10, 2023
9f53705
_traps cleanup
jakkdl Aug 10, 2023
63a8de7
cleanup
jakkdl Aug 10, 2023
deaf0bf
Merge branch 'master' into typing_improvements_
CoolCat467 Aug 16, 2023
8a4bc33
revert changes to pyproject.toml, properly merge stuff so Success: no…
jakkdl Aug 17, 2023
b038232
Merge remote-tracking branch 'origin/master' into typing_improvements_
jakkdl Aug 17, 2023
f0e18ad
_io_windows changes moved to #2761
jakkdl Aug 17, 2023
cd4e907
move around in pyproject.toml
jakkdl Aug 17, 2023
69b7e77
cleanup
jakkdl Aug 17, 2023
47a7228
make CI run without -m
jakkdl Aug 17, 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
6 changes: 3 additions & 3 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ fi
flake8 trio/ || EXIT_STATUS=$?

# Run mypy on all supported platforms
mypy -m trio -m trio.testing --platform linux || EXIT_STATUS=$?
mypy -m trio -m trio.testing --platform darwin || EXIT_STATUS=$? # tests FreeBSD too
mypy -m trio -m trio.testing --platform win32 || EXIT_STATUS=$?
mypy trio --platform linux || EXIT_STATUS=$?
mypy trio --platform darwin || EXIT_STATUS=$? # tests FreeBSD too
mypy trio --platform win32 || EXIT_STATUS=$?

# Check pip compile is consistent
pip-compile test-requirements.in
Expand Down
100 changes: 44 additions & 56 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,70 +34,58 @@ warn_redundant_casts = true
warn_return_any = true

# Avoid subtle backsliding
#disallow_any_decorated = true
#disallow_incomplete_defs = true
#disallow_subclassing_any = true
disallow_any_decorated = true
disallow_any_generics = true
disallow_any_unimported = false # Enable once Outcome has stubs.
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_decorators = true
disallow_untyped_defs = true

# Enable gradually / for new modules
# Enable once other problems are dealt with
check_untyped_defs = false
disallow_untyped_calls = false
disallow_untyped_defs = false

# DO NOT use `ignore_errors`; it doesn't apply
# downstream and users have to deal with them.
[[tool.mypy.overrides]]
# Fully typed, enable stricter checks
module = [
"trio._abc",
"trio._core._asyncgens",
"trio._core._entry_queue",
"trio._core._generated_io_epoll",
"trio._core._generated_io_kqueue",
"trio._core._generated_run",
"trio._core._io_epoll",
"trio._core._io_kqueue",
"trio._core._local",
"trio._core._multierror",
"trio._core._run",
"trio._core._thread_cache",
"trio._core._traps",
"trio._core._unbounded_queue",
"trio._core._unbounded_queue",
"trio._deprecate",
"trio._dtls",
"trio._file_io",
"trio._highlevel_open_tcp_stream",
"trio._ki",
"trio._socket",
"trio._subprocess",
"trio._subprocess_platform",
"trio._subprocess_platform.kqueue",
"trio._subprocess_platform.waitid",
"trio._subprocess_platform.windows",
"trio._sync",
"trio._threads",
"trio._tools.gen_exports",
"trio._util",
]
disallow_incomplete_defs = true
disallow_untyped_defs = true
disallow_untyped_decorators = true
disallow_any_generics = true
disallow_any_decorated = true
disallow_any_unimported = false # Enable once outcome has stubs.
disallow_subclassing_any = true

# files not yet fully typed
[[tool.mypy.overrides]]
# Needs to use Any due to some complex introspection.
module = [
"trio._path",
# 2747
"trio/testing/_network",
"trio/testing/_trio_test",
"trio/testing/_checkpoints",
"trio/testing/_check_streams",
"trio/testing/_memory_streams",
# 2745
"trio/_ssl",
# 2756
"trio/_highlevel_open_unix_stream",
"trio/_highlevel_serve_listeners",
"trio/_highlevel_ssl_helpers",
"trio/_highlevel_socket",
# 2755
"trio/_core/_windows_cffi",
"trio/_wait_for_object",
# 2761
"trio/_core/_generated_io_windows",
"trio/_core/_io_windows",


"trio/_signals",

# internal
"trio/_windows_pipes",

# tests
"trio/_core/_tests/*",
"trio/_tests/*",
"trio/testing/_fake_net", # 30
]
disallow_incomplete_defs = true
disallow_untyped_defs = true
#disallow_any_generics = true
#disallow_any_decorated = true
disallow_any_unimported = true
disallow_subclassing_any = true
disallow_any_decorated = false
disallow_any_generics = false
disallow_any_unimported = false
disallow_incomplete_defs = false
disallow_untyped_defs = false

[tool.pytest.ini_options]
addopts = ["--strict-markers", "--strict-config"]
Expand Down
2 changes: 1 addition & 1 deletion trio/_core/_generated_run.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion trio/_core/_io_common.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from __future__ import annotations

import copy
from typing import TYPE_CHECKING

import outcome

from .. import _core

if TYPE_CHECKING:
from ._io_epoll import EpollWaiters


# Utility function shared between _io_epoll and _io_windows
def wake_all(waiters, exc):
def wake_all(waiters: EpollWaiters, exc: BaseException) -> None:
try:
current_task = _core.current_task()
except RuntimeError:
Expand Down
8 changes: 5 additions & 3 deletions trio/_core/_ki.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def currently_ki_protected() -> bool:
# see python-trio/async_generator/async_generator/_impl.py
def legacy_isasyncgenfunction(
obj: object,
) -> TypeGuard[Callable[..., types.AsyncGeneratorType]]:
) -> TypeGuard[Callable[..., types.AsyncGeneratorType[object, object]]]:
return getattr(obj, "_async_gen_function", None) == id(obj)


Expand Down Expand Up @@ -196,7 +196,9 @@ def wrapper(*args: ArgsT.args, **kwargs: ArgsT.kwargs) -> RetT:

@attr.s
class KIManager:
handler = attr.ib(default=None)
handler: Callable[[int, types.FrameType | None], None] | None = attr.ib(
default=None
)

def install(
self,
Expand All @@ -221,7 +223,7 @@ def handler(signum: int, frame: types.FrameType | None) -> None:
self.handler = handler
signal.signal(signal.SIGINT, handler)

def close(self):
def close(self) -> None:
if self.handler is not None:
if signal.getsignal(signal.SIGINT) is self.handler:
signal.signal(signal.SIGINT, signal.default_int_handler)
Expand Down
2 changes: 1 addition & 1 deletion trio/_core/_parking_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async def park(self) -> None:
self._parked[task] = None
task.custom_sleep_data = self

def abort_fn(_):
def abort_fn(_: _core.RaiseCancelT) -> _core.Abort:
del task.custom_sleep_data._parked[task]
return _core.Abort.SUCCEEDED

Expand Down
13 changes: 8 additions & 5 deletions trio/_core/_tests/test_io.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations

import random
import socket as stdlib_socket
from contextlib import suppress
from typing import Callable

import pytest

Expand Down Expand Up @@ -47,15 +50,15 @@ def fileno_wrapper(fileobj):
return fileno_wrapper


wait_readable_options = [trio.lowlevel.wait_readable]
wait_writable_options = [trio.lowlevel.wait_writable]
notify_closing_options = [trio.lowlevel.notify_closing]
wait_readable_options: list[Callable] = [trio.lowlevel.wait_readable]
wait_writable_options: list[Callable] = [trio.lowlevel.wait_writable]
notify_closing_options: list[Callable] = [trio.lowlevel.notify_closing]

for options_list in [
for options_list in (
wait_readable_options,
wait_writable_options,
notify_closing_options,
]:
):
options_list += [using_fileno(f) for f in options_list]

# Decorators that feed in different settings for wait_readable / wait_writable
Expand Down
10 changes: 8 additions & 2 deletions trio/_core/_tests/test_ki.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from __future__ import annotations

import contextlib
import inspect
import signal
import threading
from typing import TYPE_CHECKING

import outcome
import pytest
Expand All @@ -16,6 +19,9 @@
from ..._util import signal_raise
from ...testing import wait_all_tasks_blocked

if TYPE_CHECKING:
from ..._core import Abort, RaiseCancelT


def ki_self():
signal_raise(signal.SIGINT)
Expand Down Expand Up @@ -375,7 +381,7 @@ async def main():
ki_self()
task = _core.current_task()

def abort(_):
def abort(_: RaiseCancelT) -> Abort:
_core.reschedule(task, outcome.Value(1))
return _core.Abort.FAILED

Expand All @@ -394,7 +400,7 @@ async def main():
ki_self()
task = _core.current_task()

def abort(raise_cancel):
def abort(raise_cancel: RaiseCancelT) -> Abort:
result = outcome.capture(raise_cancel)
_core.reschedule(task, result)
return _core.Abort.FAILED
Expand Down
2 changes: 1 addition & 1 deletion trio/_core/_tests/test_multierror.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ def test_apport_excepthook_monkeypatch_interaction():


@pytest.mark.parametrize("protocol", range(0, pickle.HIGHEST_PROTOCOL + 1))
def test_pickle_multierror(protocol) -> None:
def test_pickle_multierror(protocol: int) -> None:
# use trio.MultiError to make sure that pickle works through the deprecation layer
import trio

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

import trio

raise trio.MultiError([KeyError("key_error"), ValueError("value_error")])
raise trio.MultiError([KeyError("key_error"), ValueError("value_error")]) # type: ignore[attr-defined]
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ def custom_exc_hook(etype, value, tb, tb_offset=None):

# The custom excepthook should run, because Trio was polite and didn't
# override it
raise trio.MultiError([ValueError(), KeyError()])
raise trio.MultiError([ValueError(), KeyError()]) # type: ignore[attr-defined]
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def exc2_fn():


# This should be printed nicely, because Trio overrode sys.excepthook
raise trio.MultiError([exc1_fn(), exc2_fn()])
raise trio.MultiError([exc1_fn(), exc2_fn()]) # type: ignore[attr-defined]
4 changes: 2 additions & 2 deletions trio/_core/_tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,7 @@ async def test_Nursery_private_init():
def test_Nursery_subclass():
with pytest.raises(TypeError):

class Subclass(_core._run.Nursery):
class Subclass(_core._run.Nursery): # type: ignore[misc]
pass


Expand Down Expand Up @@ -1984,7 +1984,7 @@ class Subclass(_core.Cancelled):
def test_CancelScope_subclass():
with pytest.raises(TypeError):

class Subclass(_core.CancelScope):
class Subclass(_core.CancelScope): # type: ignore[misc]
pass


Expand Down
16 changes: 9 additions & 7 deletions trio/_core/_wakeup_socketpair.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import signal
import socket
import warnings
Expand All @@ -7,7 +9,7 @@


class WakeupSocketpair:
def __init__(self):
def __init__(self) -> None:
self.wakeup_sock, self.write_sock = socket.socketpair()
self.wakeup_sock.setblocking(False)
self.write_sock.setblocking(False)
Expand All @@ -27,26 +29,26 @@ def __init__(self):
self.write_sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
except OSError:
pass
self.old_wakeup_fd = None
self.old_wakeup_fd: int | None = None

def wakeup_thread_and_signal_safe(self):
def wakeup_thread_and_signal_safe(self) -> None:
try:
self.write_sock.send(b"\x00")
except BlockingIOError:
pass

async def wait_woken(self):
async def wait_woken(self) -> None:
await _core.wait_readable(self.wakeup_sock)
self.drain()

def drain(self):
def drain(self) -> None:
try:
while True:
self.wakeup_sock.recv(2**16)
except BlockingIOError:
pass

def wakeup_on_signals(self):
def wakeup_on_signals(self) -> None:
assert self.old_wakeup_fd is None
if not is_main_thread():
return
Expand All @@ -64,7 +66,7 @@ def wakeup_on_signals(self):
)
)

def close(self):
def close(self) -> None:
self.wakeup_sock.close()
self.write_sock.close()
if self.old_wakeup_fd is not None:
Expand Down
8 changes: 4 additions & 4 deletions trio/_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ async def wrapper(self: Path, *args: P.args, **kwargs: P.kwargs) -> Path:

def classmethod_wrapper_factory(
cls: AsyncAutoWrapperType, meth_name: str
) -> classmethod:
) -> classmethod: # type: ignore[type-arg]
@async_wraps(cls, cls._wraps, meth_name)
async def wrapper(cls: type[Path], *args: Any, **kwargs: Any) -> Path:
async def wrapper(cls: type[Path], *args: Any, **kwargs: Any) -> Path: # type: ignore[misc] # contains Any
meth = getattr(cls._wraps, meth_name)
func = partial(meth, *args, **kwargs)
value = await trio.to_thread.run_sync(func)
Expand Down Expand Up @@ -163,7 +163,7 @@ def generate_forwards(cls, attrs: dict[str, object]) -> None:

def generate_wraps(cls, attrs: dict[str, object]) -> None:
# generate wrappers for functions of _wraps
wrapper: classmethod | Callable
wrapper: classmethod | Callable[..., object] # type: ignore[type-arg]
for attr_name, attr in cls._wraps.__dict__.items():
# .z. exclude cls._wrap_iter
if attr_name.startswith("_") or attr_name in attrs:
Expand All @@ -188,7 +188,7 @@ def generate_magic(cls, attrs: dict[str, object]) -> None:

def generate_iter(cls, attrs: dict[str, object]) -> None:
# generate wrappers for methods that return iterators
wrapper: Callable
wrapper: Callable[..., object]
for attr_name, attr in cls._wraps.__dict__.items():
if attr_name in cls._wrap_iter:
wrapper = iter_wrapper_factory(cls, attr_name)
Expand Down
Loading