Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🗑️ Deprecate support for is_flag and flag_value parameters #987

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tests/test_deprecation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from typing import Optional

import pytest
import typer
from typer.testing import CliRunner

runner = CliRunner()


def test_deprecation():
app = typer.Typer()

def add_command():
@app.command()
def cmd(
opt: Optional[float] = typer.Option(
3.14,
is_flag=True,
flag_value="42",
help="Some wonderful number",
),
): ... # pragma: no cover

with pytest.warns(
match="The 'is_flag' and 'flag_value' parameters are not supported by Typer"
):
add_command()
2 changes: 0 additions & 2 deletions typer/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,13 @@ def _install_completion_placeholder_function(
install_completion: bool = Option(
None,
"--install-completion",
is_flag=True,
callback=install_callback,
expose_value=False,
help="Install completion for the current shell.",
),
show_completion: bool = Option(
None,
"--show-completion",
is_flag=True,
Copy link
Member Author

@svlandeg svlandeg Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we had these is_flag specifications here. I think we can just remove them, because we removed the parameter_info.is_flag is not False condition. Would be good if you could double check, @tiangolo 🙏

callback=show_callback,
expose_value=False,
help="Show completion for the current shell, to copy it or customize the installation.",
Expand Down
2 changes: 0 additions & 2 deletions typer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ def __init__(
prompt_required: bool = True,
hide_input: bool = False,
is_flag: Optional[bool] = None,
flag_value: Optional[Any] = None,
multiple: bool = False,
count: bool = False,
allow_from_autoenv: bool = True,
Expand All @@ -440,7 +439,6 @@ def __init__(
confirmation_prompt=confirmation_prompt,
hide_input=hide_input,
is_flag=is_flag,
flag_value=flag_value,
multiple=multiple,
count=count,
allow_from_autoenv=allow_from_autoenv,
Expand Down
3 changes: 1 addition & 2 deletions typer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ def get_click_param(
if is_tuple:
convertor = 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:
if main_type is bool:
is_flag = True
# Click doesn't accept a flag of type bool, only None, and then it sets it
# to bool internally
Expand All @@ -907,7 +907,6 @@ def get_click_param(
prompt_required=parameter_info.prompt_required,
hide_input=parameter_info.hide_input,
is_flag=is_flag,
flag_value=parameter_info.flag_value,
multiple=is_list,
count=parameter_info.count,
allow_from_autoenv=parameter_info.allow_from_autoenv,
Expand Down
12 changes: 10 additions & 2 deletions typer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def __init__(
confirmation_prompt: bool = False,
prompt_required: bool = True,
hide_input: bool = False,
# TODO: remove is_flag and flag_value in a future release
is_flag: Optional[bool] = None,
flag_value: Optional[Any] = None,
count: bool = False,
Expand Down Expand Up @@ -378,12 +379,19 @@ def __init__(
# Rich settings
rich_help_panel=rich_help_panel,
)
if is_flag is not None or flag_value is not None:
import warnings

warnings.warn(
"The 'is_flag' and 'flag_value' parameters are not supported by Typer "
"and will be removed entirely in a future release.",
DeprecationWarning,
stacklevel=2,
)
self.prompt = prompt
self.confirmation_prompt = confirmation_prompt
self.prompt_required = prompt_required
self.hide_input = hide_input
self.is_flag = is_flag
self.flag_value = flag_value
self.count = count
self.allow_from_autoenv = allow_from_autoenv

Expand Down
3 changes: 3 additions & 0 deletions typer/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def Option(
confirmation_prompt: bool = False,
prompt_required: bool = True,
hide_input: bool = False,
# TODO: remove is_flag and flag_value in a future release
is_flag: Optional[bool] = None,
flag_value: Optional[Any] = None,
count: bool = False,
Expand Down Expand Up @@ -98,6 +99,7 @@ def Option(
confirmation_prompt: bool = False,
prompt_required: bool = True,
hide_input: bool = False,
# TODO: remove is_flag and flag_value in a future release
is_flag: Optional[bool] = None,
flag_value: Optional[Any] = None,
count: bool = False,
Expand Down Expand Up @@ -160,6 +162,7 @@ def Option(
confirmation_prompt: bool = False,
prompt_required: bool = True,
hide_input: bool = False,
# TODO: remove is_flag and flag_value in a future release
is_flag: Optional[bool] = None,
flag_value: Optional[Any] = None,
count: bool = False,
Expand Down
Loading