Skip to content
Myr

Fix is_bool_flag being set to True even if is_flag is False

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

Fixes #1925.

authored by Gianluca Gippetto · committed by David Lord · parent da2b658 · Browse files · 3 files+24 added−1 removed
This commit

State

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

Diff stats

3 files+24 added−1 removed

  • tests:+20 added−0 removed
  • other:+4 added−1 removed

3 files+24 added−1 removed

modified:src/click/core.py+1 added-1 removed
2526 unmodified lines
2527 # default.2528 self.type = types.convert_type(None, flag_value)25292530 self.is_flag: bool = is_flag2531 self.is_bool_flag = isinstance(self.type, types.BoolParamType)2531 self.is_bool_flag = is_flag and isinstance(self.type, types.BoolParamType)2532 self.flag_value: t.Any = flag_value25332534 # Counting2535 self.count = count
422 unmodified lines
modified:tests/test_options.py+20 added
2 unmodified lines
34import pytest56import click7from click import Option8910def test_prefixes(runner):11 @click.command()
751 unmodified lines
763 param = click.Option(["-a", "x"], default=True, flag_value=4)764 assert param.type is click.INT765 param = click.Option(["-b", "x"], flag_value=8)766 assert param.type is click.INT767768769@pytest.mark.parametrize(770 ("option", "expected"),771 [772 # Not boolean flags773 pytest.param(Option(["-a"], type=int), False, id="int option"),774 pytest.param(Option(["-a"], type=bool), False, id="bool non-flag [None]"),775 pytest.param(Option(["-a"], default=True), False, id="bool non-flag [True]"),776 pytest.param(Option(["-a"], default=False), False, id="bool non-flag [False]"),777 pytest.param(Option(["-a"], flag_value=1), False, id="non-bool flag_value"),778 # Boolean flags779 pytest.param(Option(["-a"], is_flag=True), True, id="is_flag=True"),780 pytest.param(Option(["-a/-A"]), True, id="secondary option [implicit flag]"),781 pytest.param(Option(["-a"], flag_value=True), True, id="bool flag_value"),782 ],783)784def test_is_bool_flag_is_correctly_set(option, expected):785 assert option.is_bool_flag is expected
modified:CHANGES.rst+3 added
3 unmodified lines
4-------------56Unreleased78- ``is_bool_flag`` is not set to ``True`` if ``is_flag`` is ``False``.9 :issue:`1925`101112Version 8.0.113-------------1415Released 2021-05-19
887 unmodified lines