Skip to content

Commit

Permalink
Fix a few typos
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Kirsche committed Oct 23, 2024
1 parent cc6623c commit ed7c0cb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion docs/help-typer.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Here's what to have in mind and how to review a pull request:

* Don't worry too much about things like commit message styles, I will squash and merge customizing the commit manually.

* Also don't worry about style rules, there are already automatized tools checking that.
* Also don't worry about style rules, there are already automated tools checking that.

And if there's any other style or consistency need, I'll ask directly for that, or I'll add commits on top with the needed changes.

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/options/required.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The same way as with `typer.Argument()`, the old style of using the function par

////

Or you can explictily pass `...` to `typer.Option(default=...)`:
Or you can explicitly pass `...` to `typer.Option(default=...)`:

//// tab | Python 3.7+ non-Annotated

Expand Down
10 changes: 5 additions & 5 deletions tests/test_tutorial/test_subcommands/test_tutorial003.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_items_create(app):
result = runner.invoke(app, ["items", "create", "Wand"])
assert result.exit_code == 0
assert "Creating item: Wand" in result.output
# For coverage, becauses the monkeypatch above sometimes confuses coverage
# For coverage, because the monkeypatch above sometimes confuses coverage
result = runner.invoke(items.app, ["create", "Wand"])
assert result.exit_code == 0
assert "Creating item: Wand" in result.output
Expand All @@ -59,7 +59,7 @@ def test_items_sell(app):
result = runner.invoke(app, ["items", "sell", "Vase"])
assert result.exit_code == 0
assert "Selling item: Vase" in result.output
# For coverage, becauses the monkeypatch above sometimes confuses coverage
# For coverage, because the monkeypatch above sometimes confuses coverage
result = runner.invoke(items.app, ["sell", "Vase"])
assert result.exit_code == 0
assert "Selling item: Vase" in result.output
Expand All @@ -69,7 +69,7 @@ def test_items_delete(app):
result = runner.invoke(app, ["items", "delete", "Vase"])
assert result.exit_code == 0
assert "Deleting item: Vase" in result.output
# For coverage, becauses the monkeypatch above sometimes confuses coverage
# For coverage, because the monkeypatch above sometimes confuses coverage
result = runner.invoke(items.app, ["delete", "Vase"])
assert result.exit_code == 0
assert "Deleting item: Vase" in result.output
Expand All @@ -89,7 +89,7 @@ def test_users_create(app):
result = runner.invoke(app, ["users", "create", "Camila"])
assert result.exit_code == 0
assert "Creating user: Camila" in result.output
# For coverage, becauses the monkeypatch above sometimes confuses coverage
# For coverage, because the monkeypatch above sometimes confuses coverage
result = runner.invoke(users.app, ["create", "Camila"])
assert result.exit_code == 0
assert "Creating user: Camila" in result.output
Expand All @@ -99,7 +99,7 @@ def test_users_delete(app):
result = runner.invoke(app, ["users", "delete", "Camila"])
assert result.exit_code == 0
assert "Deleting user: Camila" in result.output
# For coverage, becauses the monkeypatch above sometimes confuses coverage
# For coverage, because the monkeypatch above sometimes confuses coverage
result = runner.invoke(users.app, ["delete", "Camila"])
assert result.exit_code == 0
assert "Deleting user: Camila" in result.output
Expand Down
66 changes: 33 additions & 33 deletions typer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def get_group_from_info(
solved_info = solve_typer_info_defaults(group_info)
(
params,
convertors,
converters,
context_param_name,
) = get_params_convertors_ctx_param_name_from_function(solved_info.callback)
cls = solved_info.cls or TyperGroup
Expand All @@ -529,7 +529,7 @@ def get_group_from_info(
callback=get_callback(
callback=solved_info.callback,
params=params,
convertors=convertors,
converters=converters,
context_param_name=context_param_name,
pretty_exceptions_short=pretty_exceptions_short,
),
Expand All @@ -556,19 +556,19 @@ def get_params_convertors_ctx_param_name_from_function(
callback: Optional[Callable[..., Any]],
) -> Tuple[List[Union[click.Argument, click.Option]], Dict[str, Any], Optional[str]]:
params = []
convertors = {}
converters = {}
context_param_name = None
if callback:
parameters = get_params_from_function(callback)
for param_name, param in parameters.items():
if lenient_issubclass(param.annotation, click.Context):
context_param_name = param_name
continue
click_param, convertor = get_click_param(param)
if convertor:
convertors[param_name] = convertor
click_param, converter = get_click_param(param)
if converter:
converters[param_name] = converter
params.append(click_param)
return params, convertors, context_param_name
return params, converters, context_param_name


def get_command_from_info(
Expand All @@ -586,7 +586,7 @@ def get_command_from_info(
use_help = inspect.cleandoc(use_help)
(
params,
convertors,
converters,
context_param_name,
) = get_params_convertors_ctx_param_name_from_function(command_info.callback)
cls = command_info.cls or TyperCommand
Expand All @@ -596,7 +596,7 @@ def get_command_from_info(
callback=get_callback(
callback=command_info.callback,
params=params,
convertors=convertors,
converters=converters,
context_param_name=context_param_name,
pretty_exceptions_short=pretty_exceptions_short,
),
Expand All @@ -617,12 +617,12 @@ def get_command_from_info(


def determine_type_convertor(type_: Any) -> Optional[Callable[[Any], Any]]:
convertor: Optional[Callable[[Any], Any]] = None
converter: Optional[Callable[[Any], Any]] = None
if lenient_issubclass(type_, Path):
convertor = param_path_convertor
converter = param_path_convertor
if lenient_issubclass(type_, Enum):
convertor = generate_enum_convertor(type_)
return convertor
converter = generate_enum_convertor(type_)
return converter


def param_path_convertor(value: Optional[str] = None) -> Optional[Path]:
Expand All @@ -634,40 +634,40 @@ def param_path_convertor(value: Optional[str] = None) -> Optional[Path]:
def generate_enum_convertor(enum: Type[Enum]) -> Callable[[Any], Any]:
val_map = {str(val.value): val for val in enum}

def convertor(value: Any) -> Any:
def converter(value: Any) -> Any:
if value is not None:
val = str(value)
if val in val_map:
key = val_map[val]
return enum(key)

return convertor
return converter


def generate_list_convertor(
convertor: Optional[Callable[[Any], Any]], default_value: Optional[Any]
converter: Optional[Callable[[Any], Any]], default_value: Optional[Any]
) -> Callable[[Sequence[Any]], Optional[List[Any]]]:
def internal_convertor(value: Sequence[Any]) -> Optional[List[Any]]:
if default_value is None and len(value) == 0:
return None
return [convertor(v) if convertor else v for v in value]
return [converter(v) if converter else v for v in value]

return internal_convertor


def generate_tuple_convertor(
types: Sequence[Any],
) -> Callable[[Optional[Tuple[Any, ...]]], Optional[Tuple[Any, ...]]]:
convertors = [determine_type_convertor(type_) for type_ in types]
converters = [determine_type_convertor(type_) for type_ in types]

def internal_convertor(
param_args: Optional[Tuple[Any, ...]],
) -> Optional[Tuple[Any, ...]]:
if param_args is None:
return None
return tuple(
convertor(arg) if convertor else arg
for (convertor, arg) in zip(convertors, param_args)
converter(arg) if converter else arg
for (converter, arg) in zip(converters, param_args)
)

return internal_convertor
Expand All @@ -677,11 +677,11 @@ def get_callback(
*,
callback: Optional[Callable[..., Any]] = None,
params: Sequence[click.Parameter] = [],
convertors: Optional[Dict[str, Callable[[str], Any]]] = None,
converters: Optional[Dict[str, Callable[[str], Any]]] = None,
context_param_name: Optional[str] = None,
pretty_exceptions_short: bool,
) -> Optional[Callable[..., Any]]:
use_convertors = convertors or {}
use_convertors = converters or {}
if not callback:
return None
parameters = get_params_from_function(callback)
Expand Down Expand Up @@ -872,13 +872,13 @@ def get_click_param(
parameter_type = get_click_type(
annotation=main_type, parameter_info=parameter_info
)
convertor = determine_type_convertor(main_type)
converter = determine_type_convertor(main_type)
if is_list:
convertor = generate_list_convertor(
convertor=convertor, default_value=default_value
converter = generate_list_convertor(
converter=converter, default_value=default_value
)
if is_tuple:
convertor = generate_tuple_convertor(get_args(main_type))
converter = generate_tuple_convertor(get_args(main_type))
if isinstance(parameter_info, OptionInfo):
if main_type is bool and parameter_info.is_flag is not False:
is_flag = True
Expand Down Expand Up @@ -920,7 +920,7 @@ def get_click_param(
required=required,
default=default_value,
callback=get_param_callback(
callback=parameter_info.callback, convertor=convertor
callback=parameter_info.callback, converter=converter
),
metavar=parameter_info.metavar,
expose_value=parameter_info.expose_value,
Expand All @@ -931,7 +931,7 @@ def get_click_param(
# Rich settings
rich_help_panel=parameter_info.rich_help_panel,
),
convertor,
converter,
)
elif isinstance(parameter_info, ArgumentInfo):
param_decls = [param.name]
Expand All @@ -954,7 +954,7 @@ def get_click_param(
# Parameter
default=default_value,
callback=get_param_callback(
callback=parameter_info.callback, convertor=convertor
callback=parameter_info.callback, converter=converter
),
metavar=parameter_info.metavar,
expose_value=parameter_info.expose_value,
Expand All @@ -965,15 +965,15 @@ def get_click_param(
# Rich settings
rich_help_panel=parameter_info.rich_help_panel,
),
convertor,
converter,
)
raise AssertionError("A click.Parameter should be returned") # pragma: no cover


def get_param_callback(
*,
callback: Optional[Callable[..., Any]] = None,
convertor: Optional[Callable[..., Any]] = None,
converter: Optional[Callable[..., Any]] = None,
) -> Optional[Callable[..., Any]]:
if not callback:
return None
Expand Down Expand Up @@ -1011,8 +1011,8 @@ def wrapper(ctx: click.Context, param: click.Parameter, value: Any) -> Any:
if click_param_name:
use_params[click_param_name] = param
if value_name:
if convertor:
use_value = convertor(value)
if converter:
use_value = converter(value)
else:
use_value = value
use_params[value_name] = use_value
Expand Down

0 comments on commit ed7c0cb

Please sign in to comment.