Skip to content

Commit f046590

Browse files
authored
Merge pull request #19 from oremanj/acceptmore
Fix some false positives
2 parents cec85c1 + 83e0938 commit f046590

File tree

9 files changed

+45
-45
lines changed

9 files changed

+45
-45
lines changed

async_generator-stubs/__init__.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ def aclosing(obj: _T_closeable) -> AsyncContextManager[_T_closeable]: ...
5757
_AsyncGenHooks = NamedTuple(
5858
"AsyncGenHooks",
5959
[
60-
("firstiter", Optional[Callable[[AsyncGenerator[Any, Any]], None]]),
61-
("finalizer", Optional[Callable[[AsyncGenerator[Any, Any]], None]]),
60+
("firstiter", Optional[Callable[[AsyncGenerator[Any, Any]], Any]]),
61+
("finalizer", Optional[Callable[[AsyncGenerator[Any, Any]], Any]]),
6262
],
6363
)
6464

6565
def get_asyncgen_hooks() -> _AsyncGenHooks: ...
6666
def set_asyncgen_hooks(
67-
firstiter: Optional[Callable[[AsyncGenerator[Any, Any]], None]] = ...,
68-
finalizer: Optional[Callable[[AsyncGenerator[Any, Any]], None]] = ...,
67+
firstiter: Optional[Callable[[AsyncGenerator[Any, Any]], Any]] = ...,
68+
finalizer: Optional[Callable[[AsyncGenerator[Any, Any]], Any]] = ...,
6969
) -> None: ...

trio-stubs/__init__.pyi

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ class Nursery(_NotConstructible, metaclass=ABCMeta):
117117
def start_soon(
118118
self,
119119
async_fn: Union[
120-
# List these explicitly instead of Callable[..., Awaitable[None]]
120+
# List these explicitly instead of Callable[..., Awaitable[Any]]
121121
# so that even without the plugin we catch cases of passing a
122122
# function with keyword-only arguments to start_soon().
123-
Callable[[], Awaitable[None]],
124-
Callable[[Any], Awaitable[None]],
125-
Callable[[Any, Any], Awaitable[None]],
126-
Callable[[Any, Any, Any], Awaitable[None]],
127-
Callable[[Any, Any, Any, Any], Awaitable[None]],
128-
Callable[[VarArg()], Awaitable[None]],
123+
Callable[[], Awaitable[Any]],
124+
Callable[[Any], Awaitable[Any]],
125+
Callable[[Any, Any], Awaitable[Any]],
126+
Callable[[Any, Any, Any], Awaitable[Any]],
127+
Callable[[Any, Any, Any, Any], Awaitable[Any]],
128+
Callable[[VarArg()], Awaitable[Any]],
129129
],
130130
*args: Any,
131131
name: object = None,
@@ -134,24 +134,24 @@ class Nursery(_NotConstructible, metaclass=ABCMeta):
134134
async def start(
135135
self,
136136
async_fn: Union[
137-
# List these explicitly instead of Callable[..., Awaitable[None]]
137+
# List these explicitly instead of Callable[..., Awaitable[Any]]
138138
# so that even without the plugin we can infer the return type
139139
# of start(), and fail when a function is passed that doesn't
140140
# accept task_status.
141-
Callable[[NamedArg(TaskStatus[T], "task_status")], Awaitable[None]],
142-
Callable[[Any, NamedArg(TaskStatus[T], "task_status")], Awaitable[None]],
141+
Callable[[NamedArg(TaskStatus[T], "task_status")], Awaitable[Any]],
142+
Callable[[Any, NamedArg(TaskStatus[T], "task_status")], Awaitable[Any]],
143143
Callable[
144-
[Any, Any, NamedArg(TaskStatus[T], "task_status")], Awaitable[None]
144+
[Any, Any, NamedArg(TaskStatus[T], "task_status")], Awaitable[Any]
145145
],
146146
Callable[
147-
[Any, Any, Any, NamedArg(TaskStatus[T], "task_status")], Awaitable[None]
147+
[Any, Any, Any, NamedArg(TaskStatus[T], "task_status")], Awaitable[Any]
148148
],
149149
Callable[
150150
[Any, Any, Any, Any, NamedArg(TaskStatus[T], "task_status")],
151-
Awaitable[None],
151+
Awaitable[Any],
152152
],
153153
Callable[
154-
[VarArg(), NamedArg(TaskStatus[T], "task_status")], Awaitable[None]
154+
[VarArg(), NamedArg(TaskStatus[T], "task_status")], Awaitable[Any]
155155
],
156156
],
157157
*args: Any,
@@ -433,7 +433,7 @@ class Path(pathlib.PurePath):
433433
T_resource = TypeVar("T_resource", bound=trio.abc.AsyncResource)
434434

435435
async def serve_listeners(
436-
handler: Callable[[T_resource], Awaitable[None]],
436+
handler: Callable[[T_resource], Awaitable[Any]],
437437
listeners: Sequence[trio.abc.Listener[T_resource]],
438438
*,
439439
handler_nursery: Optional[Nursery] = None,
@@ -450,7 +450,7 @@ async def open_tcp_listeners(
450450
port: int, *, host: Optional[AnyStr] = None, backlog: Optional[int] = None
451451
) -> Sequence[SocketListener]: ...
452452
async def serve_tcp(
453-
handler: Callable[[SocketStream], Awaitable[None]],
453+
handler: Callable[[SocketStream], Awaitable[Any]],
454454
port: int,
455455
*,
456456
host: Optional[AnyStr] = None,
@@ -480,7 +480,7 @@ async def open_ssl_over_tcp_listeners(
480480
backlog: Optional[int] = None,
481481
) -> Sequence[trio.SSLListener]: ...
482482
async def serve_ssl_over_tcp(
483-
handler: Callable[[trio.SSLStream], Awaitable[None]],
483+
handler: Callable[[trio.SSLStream], Awaitable[Any]],
484484
port: int,
485485
ssl_context: ssl.SSLContext,
486486
*,
@@ -618,7 +618,7 @@ else:
618618
shell: Literal[True],
619619
cwd: str = ...,
620620
env: Mapping[str, str] = ...,
621-
preexec_fn: Optional[Callable[[], None]] = ...,
621+
preexec_fn: Optional[Callable[[], Any]] = ...,
622622
restore_signals: bool = ...,
623623
start_new_session: bool = ...,
624624
pass_fds: Sequence[int] = ...,
@@ -634,7 +634,7 @@ else:
634634
shell: bool = ...,
635635
cwd: str = ...,
636636
env: Mapping[str, str] = ...,
637-
preexec_fn: Optional[Callable[[], None]] = ...,
637+
preexec_fn: Optional[Callable[[], Any]] = ...,
638638
restore_signals: bool = ...,
639639
start_new_session: bool = ...,
640640
pass_fds: Sequence[int] = ...,
@@ -653,7 +653,7 @@ else:
653653
shell: Literal[True],
654654
cwd: str = ...,
655655
env: Mapping[str, str] = ...,
656-
preexec_fn: Optional[Callable[[], None]] = ...,
656+
preexec_fn: Optional[Callable[[], Any]] = ...,
657657
restore_signals: bool = ...,
658658
start_new_session: bool = ...,
659659
pass_fds: Sequence[int] = ...,
@@ -672,7 +672,7 @@ else:
672672
shell: bool = ...,
673673
cwd: str = ...,
674674
env: Mapping[str, str] = ...,
675-
preexec_fn: Optional[Callable[[], None]] = ...,
675+
preexec_fn: Optional[Callable[[], Any]] = ...,
676676
restore_signals: bool = ...,
677677
start_new_session: bool = ...,
678678
pass_fds: Sequence[int] = ...,

trio-stubs/hazmat.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class TrioToken:
3939
@takes_callable_and_args
4040
def run_sync_soon(
4141
self,
42-
sync_fn: Union[Callable[..., None], Callable[[VarArg()], None]],
42+
sync_fn: Union[Callable[..., Any], Callable[[VarArg()], Any]],
4343
*args: Any,
4444
idempotent: bool = False,
4545
) -> None: ...
@@ -75,7 +75,7 @@ def reschedule(task: Task, next_send: outcome.Outcome[Any] = ...) -> None: ...
7575
@takes_callable_and_args
7676
def spawn_system_task(
7777
async_fn: Union[
78-
Callable[..., Awaitable[None]], Callable[[VarArg()], Awaitable[None]]
78+
Callable[..., Awaitable[Any]], Callable[[VarArg()], Awaitable[Any]]
7979
],
8080
*args: Any,
8181
name: object = ...,

trio-stubs/socket.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,8 @@ class SocketType:
476476
def get_inheritable(self) -> bool: ...
477477
def set_inheritable(self, inheritable: bool) -> None: ...
478478
def fileno(self) -> int: ...
479-
def getpeername(self) -> Union[None, Tuple[Any, ...], str]: ...
480-
def getsockname(self) -> Union[None, Tuple[Any, ...], str]: ...
479+
def getpeername(self) -> Any: ...
480+
def getsockname(self) -> Any: ...
481481
@overload
482482
def getsockopt(self, level: int, optname: int) -> int: ...
483483
@overload

trio-stubs/testing.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ async def check_half_closeable_stream(
4848
stream_maker: _StreamMaker, clogged_stream_maker: Optional[_StreamMaker]
4949
) -> None: ...
5050

51-
MemoryStreamHook = Optional[Callable[[], Awaitable[None]]]
52-
MemoryStreamSyncHook = Optional[Callable[[], None]]
51+
MemoryStreamHook = Optional[Callable[[], Awaitable[Any]]]
52+
MemoryStreamSyncHook = Optional[Callable[[], Any]]
5353
@attr.s(auto_attribs=True)
5454
class MemorySendStream(trio.abc.SendStream):
5555
send_all_hook: MemoryStreamHook = ...

trio_typing/_tests/test-data/async_generator.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async def dummy():
6161
firstiter = agen.get_asyncgen_hooks().firstiter
6262
if firstiter is not None:
6363
firstiter(iter([])) # E: Argument 1 has incompatible type "Iterator[<nothing>]"; expected "AsyncGenerator[Any, Any]"
64-
reveal_type(firstiter(dummy())) # N: Revealed type is 'None'
64+
reveal_type(firstiter(dummy())) # N: Revealed type is 'Any'
6565
agen.set_asyncgen_hooks(firstiter)
6666
agen.set_asyncgen_hooks(firstiter, finalizer=firstiter)
6767

trio_typing/_tests/test-data/taskstatus.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ async def child2(
1616

1717
async def parent() -> None:
1818
async with trio.open_nursery() as nursery:
19-
nursery.start_soon(child, 10) # E: Argument 1 to "start_soon" of "Nursery" has incompatible type "Callable[[int, NamedArg(TaskStatus[int], 'task_status')], Coroutine[Any, Any, None]]"; expected "Callable[[int], Awaitable[None]]"
20-
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[None]]"
21-
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[None]]"
19+
nursery.start_soon(child, 10) # E: Argument 1 to "start_soon" of "Nursery" has incompatible type "Callable[[int, NamedArg(TaskStatus[int], 'task_status')], Coroutine[Any, Any, None]]"; expected "Callable[[int], Awaitable[Any]]"
20+
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]]"
21+
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]]"
2222
nursery.start_soon(child2, 50)
23-
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[None]]"
24-
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[None]]"
23+
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]]"
24+
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]]"
2525
result = await nursery.start(child, 10)
2626
result2 = await nursery.start(child2, 10)
2727
reveal_type(result) # N: Revealed type is 'builtins.int*'
@@ -45,7 +45,7 @@ async def child2(
4545

4646
async def parent() -> None:
4747
async with trio.open_nursery() as nursery:
48-
nursery.start_soon(child, 10) # E: Argument 1 to "start_soon" of "Nursery" has incompatible type "Callable[[int, NamedArg(TaskStatus[int], 'task_status')], Coroutine[Any, Any, None]]"; expected "Union[Callable[[], Awaitable[None]], Callable[[Any], Awaitable[None]], Callable[[Any, Any], Awaitable[None]], Callable[[Any, Any, Any], Awaitable[None]], Callable[[Any, Any, Any, Any], Awaitable[None]], Callable[[VarArg(Any)], Awaitable[None]]]"
48+
nursery.start_soon(child, 10) # E: Argument 1 to "start_soon" of "Nursery" has incompatible type "Callable[[int, NamedArg(TaskStatus[int], 'task_status')], Coroutine[Any, Any, None]]"; expected "Union[Callable[[], Awaitable[Any]], Callable[[Any], Awaitable[Any]], Callable[[Any, Any], Awaitable[Any]], Callable[[Any, Any, Any], Awaitable[Any]], Callable[[Any, Any, Any, Any], Awaitable[Any]], Callable[[VarArg(Any)], Awaitable[Any]]]"
4949
nursery.start_soon(child2)
5050
nursery.start_soon(child2, "hi")
5151
nursery.start_soon(child2, 50)

trio_typing/_tests/test-data/trio-basic.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ async def sleep_sort(values: Sequence[float]) -> List[float]:
1515
reveal_type(nursery.cancel_scope) # N: Revealed type is 'trio.CancelScope'
1616
for value in values:
1717
nursery.start_soon(worker, value)
18-
nursery.start_soon(worker) # E: Argument 1 to "start_soon" of "Nursery" has incompatible type "Callable[[float], Coroutine[Any, Any, None]]"; expected "Callable[[], Awaitable[None]]"
19-
nursery.start_soon(worker, "hi") # E: Argument 1 to "start_soon" of "Nursery" has incompatible type "Callable[[float], Coroutine[Any, Any, None]]"; expected "Callable[[str], Awaitable[None]]"
20-
nursery.start_soon(worker, value, value) # E: Argument 1 to "start_soon" of "Nursery" has incompatible type "Callable[[float], Coroutine[Any, Any, None]]"; expected "Callable[[float, float], Awaitable[None]]"
18+
nursery.start_soon(worker) # E: Argument 1 to "start_soon" of "Nursery" has incompatible type "Callable[[float], Coroutine[Any, Any, None]]"; expected "Callable[[], Awaitable[Any]]"
19+
nursery.start_soon(worker, "hi") # E: Argument 1 to "start_soon" of "Nursery" has incompatible type "Callable[[float], Coroutine[Any, Any, None]]"; expected "Callable[[str], Awaitable[Any]]"
20+
nursery.start_soon(worker, value, value) # E: Argument 1 to "start_soon" of "Nursery" has incompatible type "Callable[[float], Coroutine[Any, Any, None]]"; expected "Callable[[float, float], Awaitable[Any]]"
2121

2222
return result
2323

trio_typing/plugin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def takes_callable_and_args_callback(ctx: FunctionContext) -> Type:
410410
@trio_typing.takes_callable_and_args
411411
def start_soon(
412412
self,
413-
async_fn: Callable[[VarArg()], None],
413+
async_fn: Callable[[VarArg()], Any],
414414
*args: Any,
415415
) -> None: ...
416416
@@ -424,20 +424,20 @@ def start_soon(
424424
@overload
425425
def start_soon(
426426
self,
427-
async_fn: Callable[[], None],
427+
async_fn: Callable[[], Any],
428428
) -> None: ...
429429
430430
@overload
431431
def start_soon(
432432
self,
433-
async_fn: Callable[[T1], None],
433+
async_fn: Callable[[T1], Any],
434434
__arg1: T1,
435435
) -> None: ...
436436
437437
@overload
438438
def start_soon(
439439
self,
440-
async_fn: Callable[[T1, T2], None],
440+
async_fn: Callable[[T1, T2], Any],
441441
__arg1: T1,
442442
__arg2: T2
443443
) -> None: ...

0 commit comments

Comments
 (0)