Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6e91b75
Enable mypy's `disallow_any_explicit` flag.
CoolCat467 Oct 27, 2024
feeccf1
Fix various things after reviewing all changes
CoolCat467 Oct 27, 2024
569bc37
Do not use faster mypy cache on pypy
CoolCat467 Oct 27, 2024
deb1c13
Merge remote-tracking branch 'origin/main' into enable-disallow_any_e…
CoolCat467 Oct 27, 2024
521c1b7
Try to get rid of more `Any`s
CoolCat467 Oct 27, 2024
55964ad
Get rid of a bunch more `Any`s and resolve mypy issues
CoolCat467 Oct 28, 2024
e888514
Match other TypeVarTuple usage
CoolCat467 Oct 28, 2024
30db0d8
Mark variable as nonlocal
CoolCat467 Oct 28, 2024
7707361
Cast asyncio run in loop to be InHost
CoolCat467 Oct 28, 2024
e99b69f
Handle case where `names` does not exist in node for some reason
CoolCat467 Oct 28, 2024
aee4a77
Hopefully fix jedi issue
CoolCat467 Oct 28, 2024
e157589
Check the hashes are the same
A5rocks Oct 28, 2024
62f89fa
Get the hash glob makes
A5rocks Oct 28, 2024
ca48ef6
Fix inputs to glob.hashFiles
A5rocks Oct 28, 2024
28b4abc
Remove testing hashes
A5rocks Oct 28, 2024
a1e4916
Apply requested changes from code review
CoolCat467 Oct 28, 2024
c3c0a28
Code review suggestions
CoolCat467 Oct 28, 2024
63353f4
Fix type issue
CoolCat467 Oct 28, 2024
69e60a5
Fix cffi type issues again
CoolCat467 Oct 28, 2024
25ecf1e
Merge branch 'main' into enable-disallow_any_explicit
CoolCat467 Oct 28, 2024
2bc0da3
Use correct `CData`
CoolCat467 Oct 28, 2024
0f999b8
Fix cast again
CoolCat467 Oct 28, 2024
50adccb
Clarify comments and get rid of more `Any`s
CoolCat467 Oct 30, 2024
3a320c3
Update src/trio/_tests/test_socket.py
CoolCat467 Oct 30, 2024
03f1c4e
Apply suggestions from code review
CoolCat467 Oct 30, 2024
33f1caa
Apply suggestions from code review
CoolCat467 Oct 30, 2024
854c5cd
Update src/trio/_threads.py
CoolCat467 Oct 30, 2024
bcd3f54
Improve type annotations
CoolCat467 Oct 30, 2024
7e719a8
Merge branch 'main' into enable-disallow_any_explicit
CoolCat467 Oct 30, 2024
ee0322a
Forgot `type` and fix more type issues
CoolCat467 Oct 30, 2024
9005f98
Add typing to `orig_getaddrinfo`
CoolCat467 Oct 30, 2024
c480449
Add full typing for `_responses` and `record`
CoolCat467 Oct 30, 2024
ba24f74
Fix type issues
CoolCat467 Oct 30, 2024
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
1 change: 1 addition & 0 deletions newsfragments/3121.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve type annotations in several places by removing `Any` usage.
5 changes: 2 additions & 3 deletions src/trio/_core/_concat_tb.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ def controller( # type: ignore[no-any-unimported]
and operation.args[0] == "tb_next"
) or TYPE_CHECKING: # pragma: no cover
return tb_next
if TYPE_CHECKING:
raise RuntimeError("Should not be possible")
return operation.delegate() # Delegate is reverting to original behaviour
# Delegate is reverting to original behaviour
return operation.delegate() # type: ignore[no-any-return]

return cast(
TracebackType,
Expand Down
28 changes: 20 additions & 8 deletions src/trio/_core/_io_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from contextlib import contextmanager
from typing import (
TYPE_CHECKING,
Any,
Literal,
Protocol,
TypeVar,
cast,
)
Expand All @@ -24,6 +24,7 @@
AFDPollFlags,
CData,
CompletionModes,
CType,
ErrorCodes,
FileFlags,
Handle,
Expand Down Expand Up @@ -249,14 +250,26 @@ class AFDWaiters:
current_op: AFDPollOp | None = None


class AFDHandle(Protocol):
Handle: Handle
Status: int
Events: int


class AFDPollInfo(Protocol):
Timeout: int
NumberOfHandles: int
Exclusive: int
Handles: list[AFDHandle]


# We also need to bundle up all the info for a single op into a standalone
# object, because we need to keep all these objects alive until the operation
# finishes, even if we're throwing it away.
@attrs.frozen(eq=False)
# Explicit "Any" is not allowed
class AFDPollOp: # type: ignore[misc]
class AFDPollOp:
lpOverlapped: CData
poll_info: Any # type: ignore[misc]
poll_info: AFDPollInfo
waiters: AFDWaiters
afd_group: AFDGroup

Expand Down Expand Up @@ -685,8 +698,7 @@ def _refresh_afd(self, base_handle: Handle) -> None:

lpOverlapped = ffi.new("LPOVERLAPPED")

# Explicit "Any" is not allowed
poll_info: Any = ffi.new("AFD_POLL_INFO *") # type: ignore[misc]
poll_info = cast(AFDPollInfo, ffi.new("AFD_POLL_INFO *"))
poll_info.Timeout = 2**63 - 1 # INT64_MAX
poll_info.NumberOfHandles = 1
poll_info.Exclusive = 0
Expand All @@ -699,9 +711,9 @@ def _refresh_afd(self, base_handle: Handle) -> None:
kernel32.DeviceIoControl(
afd_group.handle,
IoControlCodes.IOCTL_AFD_POLL,
poll_info,
cast(CType, poll_info),
ffi.sizeof("AFD_POLL_INFO"),
poll_info,
cast(CType, poll_info),
ffi.sizeof("AFD_POLL_INFO"),
ffi.NULL,
lpOverlapped,
Expand Down
1 change: 0 additions & 1 deletion src/trio/_core/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,6 @@ def print_stack_for_task(task):

"""
# Ignore static typing as we're doing lots of dynamic introspection
# Explicit "Any" is not allowed
coro: Any = self.coro # type: ignore[misc]
while coro is not None:
if hasattr(coro, "cr_frame"):
Expand Down
48 changes: 13 additions & 35 deletions src/trio/_core/_tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import weakref
from contextlib import ExitStack, contextmanager, suppress
from math import inf, nan
from typing import TYPE_CHECKING, Any, NoReturn, TypeVar, cast
from typing import TYPE_CHECKING, NoReturn, TypeVar

import outcome
import pytest
Expand Down Expand Up @@ -2295,7 +2295,8 @@ async def detachable_coroutine(
await sleep(0)
nonlocal task, pdco_outcome
task = _core.current_task()
pdco_outcome = await outcome.acapture(
# `No overload variant of "acapture" matches argument types "Callable[[Outcome[object]], Coroutine[Any, Any, object]]", "Outcome[None]"`
pdco_outcome = await outcome.acapture( # type: ignore[call-overload]
_core.permanently_detach_coroutine_object,
task_outcome,
)
Expand All @@ -2308,18 +2309,11 @@ async def detachable_coroutine(
# is still iterable. At that point anything can be sent into the coroutine, so the .coro type
# is wrong.
assert pdco_outcome is None
# Explicit "Any" is not allowed
assert (
not_none(task).coro.send(
cast(Any, "be free!"), # type: ignore[misc]
)
== "I'm free!"
)
# `Argument 1 to "send" of "Coroutine" has incompatible type "str"; expected "Outcome[object]"`
assert not_none(task).coro.send("be free!") == "I'm free!" # type: ignore[arg-type]
assert pdco_outcome == outcome.Value("be free!")
with pytest.raises(StopIteration):
not_none(task).coro.send(
cast(Any, None), # type: ignore[misc]
)
not_none(task).coro.send(None) # type: ignore[arg-type]

# Check the exception paths too
task = None
Expand All @@ -2332,7 +2326,7 @@ async def detachable_coroutine(
assert not_none(task).coro.throw(throw_in) == "uh oh"
assert pdco_outcome == outcome.Error(throw_in)
with pytest.raises(StopIteration):
task.coro.send(cast(Any, None))
task.coro.send(None)

async def bad_detach() -> None:
async with _core.open_nursery():
Expand Down Expand Up @@ -2384,25 +2378,10 @@ def abort_fn(_: _core.RaiseCancelT) -> _core.Abort: # pragma: no cover
await wait_all_tasks_blocked()

# Okay, it's detached. Here's our coroutine runner:
# Explicit "Any" is not allowed
assert (
not_none(task).coro.send(
cast(Any, "not trio!"), # type: ignore[misc]
)
== 1
)
assert (
not_none(task).coro.send(
cast(Any, None), # type: ignore[misc]
)
== 2
)
assert (
not_none(task).coro.send(
cast(Any, None), # type: ignore[misc]
)
== "byebye"
)
# `Argument 1 to "send" of "Coroutine" has incompatible type "str"; expected "Outcome[object]"`
assert not_none(task).coro.send("not trio!") == 1 # type: ignore[arg-type]
assert not_none(task).coro.send(None) == 2 # type: ignore[arg-type]
assert not_none(task).coro.send(None) == "byebye" # type: ignore[arg-type]

# Now it's been reattached, and we can leave the nursery

Expand Down Expand Up @@ -2432,9 +2411,8 @@ def abort_fn(_: _core.RaiseCancelT) -> _core.Abort:
await wait_all_tasks_blocked()
assert task is not None
nursery.cancel_scope.cancel()
task.coro.send(
cast(Any, None), # type: ignore[misc]
)
# `Argument 1 to "send" of "Coroutine" has incompatible type "None"; expected "Outcome[object]"`
task.coro.send(None) # type: ignore[arg-type]

assert abort_fn_called

Expand Down
5 changes: 2 additions & 3 deletions src/trio/_core/_traps.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,9 @@ def abort(inner_raise_cancel):
return (await _async_yield(WaitTaskRescheduled(abort_func))).unwrap()


# Explicit "Any" is not allowed
async def permanently_detach_coroutine_object( # type: ignore[misc]
async def permanently_detach_coroutine_object(
final_outcome: outcome.Outcome[object],
) -> Any:
) -> object:
"""Permanently detach the current task from the Trio scheduler.

Normally, a Trio task doesn't exit until its coroutine object exits. When
Expand Down
3 changes: 1 addition & 2 deletions src/trio/_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,7 @@ async def sendto(
__address: tuple[object, ...] | str | Buffer,
) -> int: ...

# Explicit "Any" is not allowed
async def sendto(self, *args: Any) -> int: # type: ignore[misc]
async def sendto(self, *args: object) -> int:
raise NotImplementedError

if sys.platform != "win32" or (
Expand Down
Loading