Skip to content

Commit a95c08a

Browse files
committed
Fix mypy errors
One mypy:ignore is in there which I don't know how to deal with.
1 parent 1ee81e0 commit a95c08a

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

src/asyncclick/core.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
if t.TYPE_CHECKING:
5252
from collections.abc import Awaitable
53+
from typing import Any
5354

5455
from .shell_completion import CompletionItem
5556

@@ -650,7 +651,7 @@ def call_on_close(self, f: t.Callable[..., t.Any]) -> t.Callable[..., t.Any]:
650651
:param f: The function to execute on teardown.
651652
"""
652653

653-
async def _f():
654+
async def _f() -> Any:
654655
res = f()
655656
if iscoroutine(res):
656657
res = await res
@@ -1525,7 +1526,7 @@ def __call__(
15251526
_anyio_backend_options: dict[str, t.Any] | None = None,
15261527
**kwargs: t.Any,
15271528
) -> t.Any:
1528-
"""Calling the command runs it in a new :mod:`anyio` event loop.
1529+
"""Calling the command directly runs it in a new :mod:`anyio` event loop.
15291530
15301531
If you are already inside an async event loop, call
15311532
``await`` :meth:`main` instead.
@@ -1543,14 +1544,14 @@ def __call__(
15431544
opts["backend"] = _anyio_backend
15441545
if _anyio_backend_options:
15451546
opts["backend_options"] = _anyio_backend_options
1546-
return anyio.run(self._main, main, args, kwargs, **opts)
1547+
return anyio.run(self.main, main, args, kwargs, **opts) # type:ignore
15471548

15481549
async def _main(
15491550
self,
1550-
main: t.Callable[..., t.Awaitable[V]],
1551+
main: t.Callable[..., t.Awaitable[t.Any]],
15511552
args: list[t.Any],
15521553
kwargs: dict[str, t.Any],
1553-
) -> V:
1554+
) -> t.Any:
15541555
return await main(*args, **kwargs)
15551556

15561557

src/asyncclick/decorators.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def new_func(*args: P.args, **kwargs: P.kwargs) -> R:
5050

5151
def make_pass_decorator(
5252
object_type: type[T], ensure: bool = False
53-
) -> t.Callable[[t.Callable[te.Concatenate[T, P], R]], t.Callable[P, R]]:
53+
) -> t.Callable[
54+
[t.Callable[te.Concatenate[T, P], R]], t.Callable[P, t.Coroutine[t.Any, t.Any, R]]
55+
]:
5456
"""Given an object type this creates a decorator that will work
5557
similar to :func:`pass_obj` but instead of passing the object of the
5658
current context, it will find the innermost context of type
@@ -76,7 +78,7 @@ def new_func(ctx, *args, **kwargs):
7678
def decorator(
7779
f: t.Callable[te.Concatenate[T, P], R],
7880
) -> t.Callable[P, t.Coroutine[t.Any, t.Any, R]]:
79-
def new_func(*args: P.args, **kwargs: P.kwargs) -> R:
81+
def new_func(*args: P.args, **kwargs: P.kwargs) -> t.Coroutine[t.Any, t.Any, R]:
8082
ctx = get_current_context()
8183

8284
obj: T | None
@@ -101,7 +103,9 @@ def new_func(*args: P.args, **kwargs: P.kwargs) -> R:
101103

102104
def pass_meta_key(
103105
key: str, *, doc_description: str | None = None
104-
) -> t.Callable[[t.Callable[te.Concatenate[T, P], R]], t.Callable[P, R]]:
106+
) -> t.Callable[
107+
[t.Callable[te.Concatenate[T, P], R]], t.Callable[P, t.Coroutine[t.Any, t.Any, R]]
108+
]:
105109
"""Create a decorator that passes a key from
106110
:attr:`click.Context.meta` as the first argument to the decorated
107111
function.

src/asyncclick/termui.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
from .utils import LazyFile
2525

2626
if t.TYPE_CHECKING:
27-
from collections.abc import Awaitable
28-
2927
from ._termui_impl import ProgressBar
3028

3129
V = t.TypeVar("V")
@@ -173,8 +171,8 @@ async def run_prompt_func(text: str) -> str:
173171
return prompt_func(text)
174172
else:
175173

176-
def run_prompt_func(text: str) -> Awaitable[str]:
177-
return anyio.to_thread.run_sync(prompt_func, text)
174+
async def run_prompt_func(text: str) -> str:
175+
return await anyio.to_thread.run_sync(prompt_func, text)
178176

179177
if value_proc is None:
180178
value_proc = convert_type(type, default)

tests/typing/typing_aliased_group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def get_command(self, ctx: click.Context, cmd_name: str) -> click.Command | None
1919
return click.Group.get_command(self, ctx, matches[0])
2020
ctx.fail(f"Too many matches: {', '.join(sorted(matches))}")
2121

22-
def resolve_command(
22+
async def resolve_command(
2323
self, ctx: click.Context, args: list[str]
2424
) -> tuple[str | None, click.Command, list[str]]:
2525
# always return the full command name
26-
_, cmd, args = super().resolve_command(ctx, args)
26+
_, cmd, args = await super().resolve_command(ctx, args)
2727
assert cmd is not None
2828
return cmd.name, cmd, args
2929

tests/typing/typing_progressbar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from typing_extensions import assert_type
44

5-
from click import progressbar
6-
from click._termui_impl import ProgressBar
5+
from asyncclick import progressbar
6+
from asyncclick._termui_impl import ProgressBar
77

88

99
def test_length_is_int() -> None:

0 commit comments

Comments
 (0)