🗑️ 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
Provenance
- Commit
abd9b45- Tree
fe9e442- Author
Sofie Van Landeghem <svlandeg@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
c2d51f7
6 files changed+41 added−8 removed
added:tests/test_deprecation.py+27 added
1+from typing import Optional2+3+import pytest4+import typer5+from typer.testing import CliRunner6+7+runner = CliRunner()8+9+10+def test_deprecation():11+ app = typer.Typer()12+13+ 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 cover23+24+ 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 lines67 def _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 linesmodified:typer/core.py-2 removed
411 unmodified lines412 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 lines438 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 linesmodified:typer/main.py+1 added-2 removed
878 unmodified lines879 )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 = None18 unmodified lines906 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 linesmodified:typer/models.py+10 added-2 removed
296 unmodified lines297 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 lines378 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 warnings384+385+ 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_autoenv397 398 129 unmodified linesmodified:typer/params.py+3 added
33 unmodified lines34 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 lines98 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 lines161 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