Skip to content

Commit 8c5430f

Browse files
committed
💚 satisfy linter mostly
1 parent c8bb936 commit 8c5430f

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description = "Typer, build great CLIs. Easy to code. Based on Python type hints
99
authors = [
1010
{name = "Sebastián Ramírez", email = "tiangolo@gmail.com"},
1111
]
12-
requires-python = ">=3.7"
12+
requires-python = ">=3.7" # need 3.8 for typing-extensions >=4.8.0
1313
classifiers = [
1414
"Intended Audience :: Information Technology",
1515
"Intended Audience :: System Administrators",
@@ -34,7 +34,7 @@ classifiers = [
3434
]
3535
dependencies = [
3636
"click >= 8.0.0",
37-
"typing-extensions >= 3.7.4.3",
37+
"typing-extensions >= 4.8.0",
3838
]
3939
readme = "README.md"
4040
[project.urls]

typer/main.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -800,12 +800,29 @@ def lenient_issubclass(
800800
return isinstance(cls, type) and issubclass(cls, class_or_tuple)
801801

802802

803+
def _set_doc_help(param: ParamMeta, parameter_info: ParameterInfo) -> None:
804+
if not param.other_annotations:
805+
return
806+
doc_annotations = [
807+
annotation
808+
for annotation in param.other_annotations
809+
if isinstance(annotation, Doc)
810+
]
811+
if len(doc_annotations) > 1:
812+
raise MultipleDocAnnotationsError(param.name)
813+
if len(doc_annotations) == 1:
814+
doc_help = doc_annotations[0].documentation if doc_annotations else None
815+
if not getattr(parameter_info, "help", None):
816+
parameter_info.help = doc_help
817+
818+
803819
def get_click_param(
804820
param: ParamMeta,
805821
) -> Tuple[Union[click.Argument, click.Option], Any]:
806822
# First, find out what will be:
807823
# * ParamInfo (ArgumentInfo or OptionInfo)
808824
# * default_value
825+
# * help message
809826
# * required
810827
default_value = None
811828
required = False
@@ -821,18 +838,7 @@ def get_click_param(
821838
else:
822839
default_value = param.default
823840
parameter_info = OptionInfo()
824-
if param.other_annotations:
825-
doc_annotations = [
826-
annotation
827-
for annotation in param.other_annotations
828-
if isinstance(annotation, Doc)
829-
]
830-
if len(doc_annotations) > 1:
831-
raise MultipleDocAnnotationsError(param.name)
832-
if len(doc_annotations) == 1:
833-
doc_help = doc_annotations[0].documentation if doc_annotations else None
834-
if not getattr(parameter_info, "help", None):
835-
parameter_info.help = doc_help
841+
_set_doc_help(param, parameter_info)
836842
annotation: Any
837843
if param.annotation is not param.empty:
838844
annotation = param.annotation

typer/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ def __init__(
514514
name: str,
515515
default: Any = inspect.Parameter.empty,
516516
annotation: Any = inspect.Parameter.empty,
517-
other_annotations: List[Any] = None,
517+
other_annotations: Optional[List[Any]] = None,
518518
) -> None:
519519
self.name = name
520520
self.default = default

typer/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def __str__(self) -> str:
107107

108108
def _split_annotation_from_typer_annotations(
109109
base_annotation: Type[Any],
110-
) -> Tuple[Type[Any], List[ParameterInfo]]:
110+
) -> Tuple[Type[Any], List[ParameterInfo], List[Any]]:
111111
if get_origin(base_annotation) is not Annotated:
112112
return base_annotation, [], []
113113
base_annotation, *other_annotations = get_args(base_annotation)

0 commit comments

Comments
 (0)