Skip to content

Commit

Permalink
Upgrade mypy and fix updated issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lachaib committed Dec 21, 2023
1 parent a36f24d commit 23988ad
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test = [
"coverage >=6.2,<7.0",
"pytest-xdist >=1.32.0,<4.0.0",
"pytest-sugar >=0.9.4,<0.10.0",
"mypy ==0.971",
"mypy ==1.7.1",
"black >=22.3.0,<23.0.0",
"isort >=5.0.6,<6.0.0",
"rich >=10.11.0,<14.0.0",
Expand Down
4 changes: 2 additions & 2 deletions typer/completion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import sys
from typing import Any, MutableMapping, Tuple
from typing import Any, Dict, Tuple

import click

Expand Down Expand Up @@ -120,7 +120,7 @@ def completion_init() -> None:
# This is only called in new Command method, only used by Click 8.x+
def shell_complete(
cli: click.BaseCommand,
ctx_args: MutableMapping[str, Any],
ctx_args: Dict[str, Any],
prog_name: str,
complete_var: str,
instruction: str,
Expand Down
17 changes: 8 additions & 9 deletions typer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
Callable,
Dict,
List,
MutableMapping,
Optional,
Sequence,
TextIO,
Expand Down Expand Up @@ -90,14 +89,14 @@ def compat_autocompletion(

out = []

for c in autocompletion(ctx, [], incomplete): # type: ignore
for c in autocompletion(ctx, [], incomplete):
if isinstance(c, tuple):
c = CompletionItem(c[0], help=c[1])
completion_item = CompletionItem(c[0], help=c[1])
elif isinstance(c, str):
c = CompletionItem(c)
completion_item = CompletionItem(c)

if c.value.startswith(incomplete):
out.append(c)
if completion_item.value.startswith(incomplete):
out.append(completion_item)

return out

Expand Down Expand Up @@ -635,7 +634,7 @@ def _typer_format_options(
def _typer_main_shell_completion(
self: click.core.Command,
*,
ctx_args: MutableMapping[str, Any],
ctx_args: Dict[str, Any],
prog_name: str,
complete_var: Optional[str] = None,
) -> None:
Expand Down Expand Up @@ -697,7 +696,7 @@ def format_options(

def _main_shell_completion(
self,
ctx_args: MutableMapping[str, Any],
ctx_args: Dict[str, Any],
prog_name: str,
complete_var: Optional[str] = None,
) -> None:
Expand Down Expand Up @@ -759,7 +758,7 @@ def format_options(

def _main_shell_completion(
self,
ctx_args: MutableMapping[str, Any],
ctx_args: Dict[str, Any],
prog_name: str,
complete_var: Optional[str] = None,
) -> None:
Expand Down
16 changes: 9 additions & 7 deletions typer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from uuid import UUID

import click
from typing_extensions import TypeAlias

from .completion import get_completion_inspect_parameters
from .core import MarkupMode, TyperArgument, TyperCommand, TyperGroup, TyperOption
Expand Down Expand Up @@ -54,14 +55,15 @@ def is_pydantic_type(type_: Any) -> bool:
type_, pydantic.BaseModel
)

def pydantic_convertor(type_):
def pydantic_convertor(type_: type) -> Callable[[str], Any]:
"""Create a convertor for a parameter annotated with a pydantic type."""
T: TypeAlias = type_ # type: ignore[valid-type]

@pydantic.validate_call
def internal_convertor(value: type_):
def internal_convertor(value: T) -> T:
return value

def convertor(value: str):
def convertor(value: str) -> T:
try:
return internal_convertor(value)
except pydantic.ValidationError as e:
Expand Down Expand Up @@ -130,7 +132,7 @@ def except_hook(
else:
stack.append(frame)
# Type ignore ref: https://github.com/python/typeshed/pull/8244
final_stack_summary = StackSummary.from_list(stack) # type: ignore
final_stack_summary = StackSummary.from_list(stack)
tb_exc.stack = final_stack_summary
for line in tb_exc.format():
print(line, file=sys.stderr)
Expand Down Expand Up @@ -715,7 +717,7 @@ def wrapper(**kwargs: Any) -> Any:
use_params[k] = v
if context_param_name:
use_params[context_param_name] = click.get_current_context()
return callback(**use_params) # type: ignore
return callback(**use_params)

update_wrapper(wrapper, callback)
return wrapper
Expand Down Expand Up @@ -1032,7 +1034,7 @@ def wrapper(ctx: click.Context, param: click.Parameter, value: Any) -> Any:
else:
use_value = value
use_params[value_name] = use_value
return callback(**use_params) # type: ignore
return callback(**use_params)

update_wrapper(wrapper, callback)
return wrapper
Expand Down Expand Up @@ -1085,7 +1087,7 @@ def wrapper(ctx: click.Context, args: List[str], incomplete: Optional[str]) -> A
use_params[args_name] = args
if incomplete_name:
use_params[incomplete_name] = incomplete
return callback(**use_params) # type: ignore
return callback(**use_params)

update_wrapper(wrapper, callback)
return wrapper
Expand Down

0 comments on commit 23988ad

Please sign in to comment.