Skip to content
Myr

🗑️ Deprecate support for `is_flag` and `flag_value` parameters (#987)

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

authored by Sofie Van Landeghem · committed by GitHub · parent c2d51f7 · Browse files · 6 files+41 added−8 removed
This commit

State

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

Diff stats

6 files+41 added−8 removed

  • tests:+27 added−0 removed
  • other:+14 added−8 removed

6 files+41 added−8 removed

added:tests/test_deprecation.py+27 added
1from typing import Optional23import pytest4import typer5from typer.testing import CliRunner67runner = CliRunner()8910def test_deprecation():11 app = typer.Typer()1213 def add_command():14 @app.command()15 def cmd(16 opt: Optional[float] = typer.Option(17 3.14,18 is_flag=True,19 flag_value="42",20 help="Some wonderful number",21 ),22 ): ... # pragma: no cover2324 with pytest.warns(25 match="The 'is_flag' and 'flag_value' parameters are not supported by Typer"26 ):27 add_command()
modified:typer/completion.py-2 removed
66 unmodified lines
67def _install_completion_placeholder_function(68 install_completion: bool = Option(69 None,70 "--install-completion",71 is_flag=True,71 callback=install_callback,72 expose_value=False,73 help="Install completion for the current shell.",74 ),75 show_completion: bool = Option(76 None,77 "--show-completion",79 is_flag=True,78 callback=show_callback,79 expose_value=False,80 help="Show completion for the current shell, to copy it or customize the installation.",81 ),
66 unmodified lines
modified:typer/core.py-2 removed
411 unmodified lines
412 confirmation_prompt: Union[bool, str] = False,413 prompt_required: bool = True,414 hide_input: bool = False,415 is_flag: Optional[bool] = None,416 flag_value: Optional[Any] = None,416 multiple: bool = False,417 count: bool = False,418 allow_from_autoenv: bool = True,419 help: Optional[str] = None,
18 unmodified lines
438 prompt=prompt,439 confirmation_prompt=confirmation_prompt,440 hide_input=hide_input,441 is_flag=is_flag,443 flag_value=flag_value,442 multiple=multiple,443 count=count,444 allow_from_autoenv=allow_from_autoenv,445 help=help,
305 unmodified lines
modified:typer/main.py+1 added-2 removed
878 unmodified lines
879 )880 if is_tuple:881 convertor = generate_tuple_convertor(get_args(main_type))882 if isinstance(parameter_info, OptionInfo):883 if main_type is bool and parameter_info.is_flag is not False:883 if main_type is bool:884 is_flag = True885 # Click doesn't accept a flag of type bool, only None, and then it sets it886 # to bool internally887 parameter_type = None
18 unmodified lines
906 confirmation_prompt=parameter_info.confirmation_prompt,907 prompt_required=parameter_info.prompt_required,908 hide_input=parameter_info.hide_input,909 is_flag=is_flag,910 flag_value=parameter_info.flag_value,910 multiple=is_list,911 count=parameter_info.count,912 allow_from_autoenv=parameter_info.allow_from_autoenv,913 type=parameter_type,
167 unmodified lines
modified:typer/models.py+10 added-2 removed
296 unmodified lines
297 prompt: Union[bool, str] = False,298 confirmation_prompt: bool = False,299 prompt_required: bool = True,300 hide_input: bool = False,301 # TODO: remove is_flag and flag_value in a future release302 is_flag: Optional[bool] = None,303 flag_value: Optional[Any] = None,304 count: bool = False,305 allow_from_autoenv: bool = True,
72 unmodified lines
378 path_type=path_type,379 # Rich settings380 rich_help_panel=rich_help_panel,381 )382 if is_flag is not None or flag_value is not None:383 import warnings384385 warnings.warn(386 "The 'is_flag' and 'flag_value' parameters are not supported by Typer "387 "and will be removed entirely in a future release.",388 DeprecationWarning,389 stacklevel=2,390 )391 self.prompt = prompt392 self.confirmation_prompt = confirmation_prompt393 self.prompt_required = prompt_required394 self.hide_input = hide_input385 self.is_flag = is_flag386 self.flag_value = flag_value395 self.count = count396 self.allow_from_autoenv = allow_from_autoenv397398
129 unmodified lines
modified:typer/params.py+3 added
33 unmodified lines
34 prompt: Union[bool, str] = False,35 confirmation_prompt: bool = False,36 prompt_required: bool = True,37 hide_input: bool = False,38 # TODO: remove is_flag and flag_value in a future release39 is_flag: Optional[bool] = None,40 flag_value: Optional[Any] = None,41 count: bool = False,42 allow_from_autoenv: bool = True,
55 unmodified lines
98 prompt: Union[bool, str] = False,99 confirmation_prompt: bool = False,100 prompt_required: bool = True,101 hide_input: bool = False,102 # TODO: remove is_flag and flag_value in a future release103 is_flag: Optional[bool] = None,104 flag_value: Optional[Any] = None,105 count: bool = False,106 allow_from_autoenv: bool = True,
54 unmodified lines
161 prompt: Union[bool, str] = False,162 confirmation_prompt: bool = False,163 prompt_required: bool = True,164 hide_input: bool = False,165 # TODO: remove is_flag and flag_value in a future release166 is_flag: Optional[bool] = None,167 flag_value: Optional[Any] = None,168 count: bool = False,169 allow_from_autoenv: bool = True,
298 unmodified lines