Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Click v8 support Resolve #280 #302

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ classifiers = [
"License :: OSI Approved :: MIT License"
]
requires = [
"click >= 7.1.1, <7.2.0"
"click >= 8, <9"
]
description-file = "README.md"
requires-python = ">=3.6"
Expand Down
8 changes: 5 additions & 3 deletions typer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
autocompletion=autocompletion,
)

def get_help_record(self, ctx: click.Context) -> Optional[Tuple[str, str]]: # type: ignore
def get_help_record(self, ctx: click.Context) -> Optional[Tuple[str, str]]:
# Modified version of click.core.Option.get_help_record()
# to support Arguments
if self.hidden:
Expand All @@ -64,15 +64,16 @@ def get_help_record(self, ctx: click.Context) -> Optional[Tuple[str, str]]: # t
else envvar
)
extra.append(f"env var: {var_str}")
if self.default is not None and (self.show_default or ctx.show_default): # type: ignore
if self.default is not None and (self.show_default or ctx.show_default):
if isinstance(self.show_default, str):
default_string = f"({self.show_default})"
elif isinstance(self.default, (list, tuple)):
default_string = ", ".join(str(d) for d in self.default)
elif inspect.isfunction(self.default):
default_string = "(dynamic)"
else:
default_string = self.default
# FIXME?
default_string = self.default # type: ignore
extra.append(f"default: {default_string}")
if self.required:
extra.append("required")
Expand All @@ -86,6 +87,7 @@ def make_metavar(self) -> str:
# to include Argument name
if self.metavar is not None:
return self.metavar
assert self.name is not None, "self.name cannot be None"
var = self.name.upper()
if not self.required:
var = "[{}]".format(var)
Expand Down
11 changes: 9 additions & 2 deletions typer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,11 @@ def get_group_from_info(group_info: TyperInfo) -> click.Command:
commands: Dict[str, click.Command] = {}
for command_info in group_info.typer_instance.registered_commands:
command = get_command_from_info(command_info=command_info)
assert command.name is not None, "command name cannot be None"
commands[command.name] = command
for sub_group_info in group_info.typer_instance.registered_groups:
sub_group = get_group_from_info(sub_group_info)
assert sub_group.name is not None, "sub_group name cannot be None"
commands[sub_group.name] = sub_group
solved_info = solve_typer_info_defaults(group_info)
(
Expand All @@ -358,6 +360,9 @@ def get_group_from_info(group_info: TyperInfo) -> click.Command:
context_param_name,
) = get_params_convertors_ctx_param_name_from_function(solved_info.callback)
cls = solved_info.cls or click.Group
assert (
solved_info.no_args_is_help is not None
), "solved_info.no_args_is_help cannot be None."
group = cls( # type: ignore
name=solved_info.name or "",
commands=commands,
Expand Down Expand Up @@ -422,7 +427,7 @@ def get_command_from_info(command_info: CommandInfo) -> click.Command:
context_param_name,
) = get_params_convertors_ctx_param_name_from_function(command_info.callback)
cls = command_info.cls or TyperCommand
command = cls( # type: ignore
command = cls(
name=name,
context_settings=command_info.context_settings,
callback=get_callback(
Expand Down Expand Up @@ -484,6 +489,7 @@ def get_callback(
for param_name in parameters:
use_params[param_name] = None
for param in params:
assert param.name is not None, "param.name cannot be None."
use_params[param.name] = param.default

def wrapper(**kwargs: Any) -> Any:
Expand All @@ -503,6 +509,7 @@ def wrapper(**kwargs: Any) -> Any:
def get_click_type(
*, annotation: Any, parameter_info: ParameterInfo
) -> click.ParamType:
assert parameter_info.atomic is not None, "parameter_info.atomic cannot be None."
if annotation == str:
return click.STRING
elif annotation == int:
Expand Down Expand Up @@ -537,7 +544,7 @@ def get_click_type(
or parameter_info.path_type
or parameter_info.resolve_path
):
return click.Path( # type: ignore
return click.Path(
exists=parameter_info.exists,
file_okay=parameter_info.file_okay,
dir_okay=parameter_info.dir_okay,
Expand Down
3 changes: 2 additions & 1 deletion typer/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ def invoke( # type: ignore
**extra: Any,
) -> Result:
use_cli = _get_command(app)
# FIXME: type ignore?
return super().invoke(
use_cli,
args=args,
args=args, # type: ignore
input=input,
env=env,
catch_exceptions=catch_exceptions,
Expand Down