Skip to content
Myr

:bug: Fix handling of CLI parameters with multiple values

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sebastián Ramírez · committed by Sebastián Ramírez · parent 724c4bc · Browse files · 1 file+15 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+15 added−5 removed

  • other:+15 added−5 removed

1 file+15 added−5 removed

modified:typer/main.py+15 added-5 removed
460 unmodified lines
461462 return convertor463464465def generate_iter_convertor(convertor: Callable[[Any], Any]) -> Callable:466 def internal_convertor(value: Any) -> List[Any]:467 return [convertor(v) for v in value]468469 return internal_convertor470471472def get_callback(473 *,474 callback: Optional[Callable] = None,475 params: Sequence[click.Parameter] = [],
160 unmodified lines
636 origin = getattr(main_type, "__origin__", None)637 # Handle Tuples and Lists638 if lenient_issubclass(origin, List):639 main_type = main_type.__args__[0]633 assert (634 "__origin__" not in main_type640 assert not getattr(641 main_type, "__origin__", None642 ), "List types with complex sub-types are not currently supported"643 is_list = True644 elif lenient_issubclass(origin, Tuple): # type: ignore645 types = []639 for type_ in origin.__args__:640 assert (641 "__origin__" not in type_646 for type_ in main_type.__args__:647 assert not getattr(648 type_, "__origin__", None649 ), "Tuple types with complex sub-types are not currently supported"650 types.append(651 get_click_type(annotation=type_, parameter_info=parameter_info)652 )
6 unmodified lines
659 if lenient_issubclass(main_type, Path):660 convertor = param_path_convertor661 if lenient_issubclass(main_type, Enum):662 convertor = generate_enum_convertor(main_type)663 if convertor and is_list:664 convertor = generate_iter_convertor(convertor)665 # TODO: handle recursive conversion for tuples666 if isinstance(parameter_info, OptionInfo):667 if main_type is bool and not (parameter_info.is_flag is False):668 is_flag = True669 # Click doesn't accept a flag of type bool, only None, and then it sets it
74 unmodified lines