Skip to content

Commit

Permalink
Fix mypy/lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangalamb committed Apr 25, 2023
1 parent 4c8ec06 commit af327f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions typer/_typing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copied from pydantic 1.9.2 (the latest version to support python 3.6.)
# https://github.com/pydantic/pydantic/blob/v1.9.2/pydantic/typing.py
# mypy: ignore-errors

import sys
from os import PathLike
Expand Down
16 changes: 8 additions & 8 deletions typer/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import inspect
from copy import copy
from typing import Any, Callable, Dict, List, Tuple, Type, get_type_hints
from typing import Any, Callable, Dict, List, Tuple, Type, cast, get_type_hints

from typing_extensions import Annotated

Expand Down Expand Up @@ -28,7 +28,7 @@ def __init__(self, argument_name: str, param_type: Type[ParameterInfo]):
self.argument_name = argument_name
self.param_type = param_type

def __str__(self):
def __str__(self) -> str:
param_type_str = _param_type_to_user_string(self.param_type)
return (
f"{param_type_str} default value cannot be set in `Annotated`"
Expand All @@ -51,7 +51,7 @@ def __init__(
self.annotated_param_type = annotated_param_type
self.default_param_type = default_param_type

def __str__(self):
def __str__(self) -> str:
annotated_param_type_str = _param_type_to_user_string(self.annotated_param_type)
default_param_type_str = _param_type_to_user_string(self.default_param_type)
msg = f"Cannot specify {annotated_param_type_str} in `Annotated` and"
Expand All @@ -69,7 +69,7 @@ class MultipleTyperAnnotationsError(Exception):
def __init__(self, argument_name: str):
self.argument_name = argument_name

def __str__(self):
def __str__(self) -> str:
return (
"Cannot specify multiple `Annotated` Typer arguments"
f" for {self.argument_name!r}"
Expand All @@ -84,7 +84,7 @@ def __init__(self, argument_name: str, param_type: Type[ParameterInfo]):
self.argument_name = argument_name
self.param_type = param_type

def __str__(self):
def __str__(self) -> str:
param_type_str = _param_type_to_user_string(self.param_type)
return (
"Cannot specify `default_factory` and a default value together"
Expand All @@ -95,7 +95,7 @@ def __str__(self):
def _split_annotation_from_typer_annotations(
base_annotation: Type[Any],
) -> Tuple[Type[Any], List[ParameterInfo]]:
if get_origin(base_annotation) is not Annotated:
if get_origin(base_annotation) is not Annotated: # type: ignore
return base_annotation, []
base_annotation, *maybe_typer_annotations = get_args(base_annotation)
return base_annotation, [
Expand Down Expand Up @@ -144,8 +144,8 @@ def get_params_from_function(func: Callable[..., Any]) -> Dict[str, ParamMeta]:
and parameter_info.default is not ...
):
parameter_info.param_decls = (
parameter_info.default,
*parameter_info.param_decls,
cast(str, parameter_info.default),
*(parameter_info.param_decls or ()),
)
parameter_info.default = ...

Expand Down

0 comments on commit af327f1

Please sign in to comment.