Skip to content
Myr

Merge pull request #2248 from jreese/8.1.x

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

Disallow use of is_flag and multiple in options

authored by David Lord · committed by GitHub · parents afdfb12, daa2d8e · Browse files · 3 files+24 added−0 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−0 removed

  • tests:+18 added−0 removed
  • other:+6 added−0 removed

3 files+24 added−0 removed

modified:src/click/core.py+3 added
2578 unmodified lines
25792580 if self.is_flag:2581 raise TypeError("'count' is not valid with 'is_flag'.")25822583 if self.multiple and self.is_flag:2584 raise TypeError("'multiple' is not valid with 'is_flag', use 'count'.")25852586 def to_info_dict(self) -> t.Dict[str, t.Any]:2587 info_dict = super().to_info_dict()2588 info_dict.update(2589 help=self.help,
409 unmodified lines
modified:tests/test_options.py+18 added
902 unmodified lines
903 ],904)905def test_is_bool_flag_is_correctly_set(option, expected):906 assert option.is_bool_flag is expected907908909@pytest.mark.parametrize(910 ("kwargs", "message"),911 [912 ({"count": True, "multiple": True}, "'count' is not valid with 'multiple'."),913 ({"count": True, "is_flag": True}, "'count' is not valid with 'is_flag'."),914 (915 {"multiple": True, "is_flag": True},916 "'multiple' is not valid with 'is_flag', use 'count'.",917 ),918 ],919)920def test_invalid_flag_combinations(runner, kwargs, message):921 with pytest.raises(TypeError) as e:922 click.Option(["-a"], **kwargs)923924 assert message in str(e.value)
modified:CHANGES.rst+3 added
5 unmodified lines
6Unreleased78- Use verbose form of ``typing.Callable`` for ``@command`` and9 ``@group``. :issue:`2255`10- Show error when attempting to create an option with11 ``multiple=True, is_flag=True``. Use ``count`` instead.12 :issue:`2246`131415Version 8.1.216-------------
1028 unmodified lines