Skip to content

Commit 03558cb

Browse files
committed
Rename multiple_separator to separator.
1 parent 3cdd682 commit 03558cb

File tree

10 files changed

+28
-30
lines changed

10 files changed

+28
-30
lines changed

docs/tutorial/multiple-values/multiple-options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ The sum is 9.5
9191
## Passing multiple values in a single argument
9292

9393
Many users expect to be able to pass multiple arguments with a single .
94-
**Typer** supports this with the `multiple_separator` option for `typing.List[T]` types:
94+
**Typer** supports this with the `separator` option for `typing.List[T]` types:
9595

9696
=== "Python 3.7+"
9797

docs_src/multiple_values/multiple_options/tutorial003.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import typer
44

55

6-
def main(number: List[float] = typer.Option([], multiple_separator=",")):
6+
def main(number: List[float] = typer.Option([], separator=",")):
77
print(f"The sum is {sum(number)}")
88

99

docs_src/multiple_values/multiple_options/tutorial003_an.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing_extensions import Annotated
55

66

7-
def main(number: Annotated[List[float], typer.Option(multiple_separator=",")] = []):
7+
def main(number: Annotated[List[float], typer.Option(separator=",")] = []):
88
print(f"The sum is {sum(number)}")
99

1010

tests/test_others.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,10 @@ def test_multiple_options_separator_1_unsupported_separator():
262262
app = typer.Typer()
263263

264264
@app.command()
265-
def main(names: typing.List[str] = typer.Option(..., multiple_separator="\t \n")):
265+
def main(names: typing.List[str] = typer.Option(..., separator="\t \n")):
266266
pass # pragma: no cover
267267

268-
with pytest.raises(typer.UnsupportedMultipleSeparatorError) as exc_info:
268+
with pytest.raises(typer.UnsupportedSeparatorError) as exc_info:
269269
runner.invoke(app, [])
270270
assert (
271271
str(exc_info.value)
@@ -277,10 +277,10 @@ def test_multiple_options_separator_2_non_list_type():
277277
app = typer.Typer()
278278

279279
@app.command()
280-
def main(names: str = typer.Option(..., multiple_separator=",")):
280+
def main(names: str = typer.Option(..., separator=",")):
281281
pass # pragma: no cover
282282

283-
with pytest.raises(typer.MultipleSeparatorForNonListTypeError) as exc_info:
283+
with pytest.raises(typer.SeparatorForNonListTypeError) as exc_info:
284284
runner.invoke(app, [])
285285
assert (
286286
str(exc_info.value)

typer/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
from .params import Argument as Argument
3939
from .params import Option as Option
4040
from .utils import (
41-
MultipleSeparatorForNonListTypeError as MultipleSeparatorForNonListTypeError,
41+
SeparatorForNonListTypeError as SeparatorForNonListTypeError,
4242
)
4343
from .utils import (
44-
UnsupportedMultipleSeparatorError as UnsupportedMultipleSeparatorError,
44+
UnsupportedSeparatorError as UnsupportedSeparatorError,
4545
)

typer/core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def __init__(
421421
show_envvar: bool = False,
422422
# Rich settings
423423
rich_help_panel: Union[str, None] = None,
424-
multiple_separator: Optional[str] = None,
424+
separator: Optional[str] = None,
425425
):
426426
super().__init__(
427427
param_decls=param_decls,
@@ -453,16 +453,16 @@ def __init__(
453453
_typer_param_setup_autocompletion_compat(self, autocompletion=autocompletion)
454454
self.rich_help_panel = rich_help_panel
455455
self.original_type = type
456-
self.multiple_separator = multiple_separator
456+
self.separator = separator
457457

458458
def _parse_separated_parameter_list(self, parameter_values: List[str]) -> List[str]:
459459
values = []
460460
for param_str_list in parameter_values:
461-
values.extend(param_str_list.split(self.multiple_separator))
461+
values.extend(param_str_list.split(self.separator))
462462
return values
463463

464464
def process_value(self, ctx: Context, value: t.Any) -> t.Any:
465-
if self.multiple_separator is not None:
465+
if self.separator is not None:
466466
value = self._parse_separated_parameter_list(value)
467467
return super().process_value(ctx, value)
468468

typer/main.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
TyperInfo,
3636
)
3737
from .utils import (
38-
MultipleSeparatorForNonListTypeError,
39-
UnsupportedMultipleSeparatorError,
38+
SeparatorForNonListTypeError,
39+
UnsupportedSeparatorError,
4040
get_params_from_function,
4141
)
4242

@@ -890,17 +890,15 @@ def get_click_param(
890890
param_decls.append(default_option_declaration)
891891

892892
# Check the multiple separator option for validity
893-
multiple_separator = None
894-
if parameter_info.multiple_separator:
895-
multiple_separator = parameter_info.multiple_separator.strip()
893+
separator = None
894+
if parameter_info.separator:
895+
separator = parameter_info.separator.strip()
896896

897897
if not is_list:
898-
raise MultipleSeparatorForNonListTypeError(param.name, main_type)
898+
raise SeparatorForNonListTypeError(param.name, main_type)
899899

900-
if len(multiple_separator) != 1:
901-
raise UnsupportedMultipleSeparatorError(
902-
param.name, parameter_info.multiple_separator
903-
)
900+
if len(separator) != 1:
901+
raise UnsupportedSeparatorError(param.name, parameter_info.separator)
904902

905903
return (
906904
TyperOption(
@@ -935,7 +933,7 @@ def get_click_param(
935933
autocompletion=get_param_completion(parameter_info.autocompletion),
936934
# Rich settings
937935
rich_help_panel=parameter_info.rich_help_panel,
938-
multiple_separator=multiple_separator,
936+
separator=separator,
939937
),
940938
convertor,
941939
)

typer/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def __init__(
331331
path_type: Union[None, Type[str], Type[bytes]] = None,
332332
# Rich settings
333333
rich_help_panel: Union[str, None] = None,
334-
multiple_separator: Optional[str] = None,
334+
separator: Optional[str] = None,
335335
):
336336
super().__init__(
337337
default=default,
@@ -387,7 +387,7 @@ def __init__(
387387
self.flag_value = flag_value
388388
self.count = count
389389
self.allow_from_autoenv = allow_from_autoenv
390-
self.multiple_separator = multiple_separator
390+
self.separator = separator
391391

392392

393393
class ArgumentInfo(ParameterInfo):

typer/params.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def Option(
196196
# Rich settings
197197
rich_help_panel: Union[str, None] = None,
198198
# Multiple values
199-
multiple_separator: Optional[str] = None,
199+
separator: Optional[str] = None,
200200
) -> Any:
201201
return OptionInfo(
202202
# Parameter
@@ -252,7 +252,7 @@ def Option(
252252
path_type=path_type,
253253
# Rich settings
254254
rich_help_panel=rich_help_panel,
255-
multiple_separator=multiple_separator,
255+
separator=separator,
256256
)
257257

258258

typer/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def get_params_from_function(func: Callable[..., Any]) -> Dict[str, ParamMeta]:
192192
return params
193193

194194

195-
class MultipleSeparatorForNonListTypeError(Exception):
195+
class SeparatorForNonListTypeError(Exception):
196196
argument_name: str
197197
argument_type: Type[Any]
198198

@@ -204,7 +204,7 @@ def __str__(self) -> str:
204204
return f"Multiple values are supported for List[T] types only. Annotate {self.argument_name!r} as List[{self.argument_type.__name__}] to support multiple values."
205205

206206

207-
class UnsupportedMultipleSeparatorError(Exception):
207+
class UnsupportedSeparatorError(Exception):
208208
argument_name: str
209209
separator: str
210210

0 commit comments

Comments
 (0)