diff --git a/src/click/core.py b/src/click/core.py index a9a72c5f9..e43078acb 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -2580,6 +2580,10 @@ def __init__( if self.is_flag: raise TypeError("'count' is not valid with 'is_flag'.") + if self.multiple: + if self.is_flag: + raise TypeError("'multiple' is not valid with 'is_flag'.") + def to_info_dict(self) -> t.Dict[str, t.Any]: info_dict = super().to_info_dict() info_dict.update( diff --git a/tests/test_options.py b/tests/test_options.py index 2e1f29106..fb5d6129c 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -904,3 +904,31 @@ def test_type_from_flag_value(): ) def test_is_bool_flag_is_correctly_set(option, expected): assert option.is_bool_flag is expected + + +def test_invalid_flag_combinations(runner): + try: + + @click.command() + @click.option("--foo", is_flag=True, count=True) + def cli1(foo): + pass + + except TypeError as e: + assert "'count' is not valid with 'is_flag'" in str(e) + + else: + raise AssertionError("didn't raise TypeError for use of count and is_flag") + + try: + + @click.command() + @click.option("--foo", is_flag=True, multiple=True) + def cli2(foo): + pass + + except TypeError as e: + assert "'multiple' is not valid with 'is_flag'" in str(e) + + else: + raise AssertionError("didn't raise TypeError for use of multiple and is_flag")