Merge branch '8.1.x'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parents 6bd8e56, 9c6f4c8 · Browse files · 8 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
8 files+41 added−8 removed
- tests:+18 added−0 removed
- other:+23 added−8 removed
Provenance
- Commit
0aec116- Tree
c64a76b- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
6bd8e56- Parent 2
9c6f4c8
8 files changed+41 added−8 removed
modified:requirements/dev.txt+1 added-1 removed
18 unmodified lines19 filelock==3.6.020 # via21 # tox22 # virtualenv23-identify==2.4.1223+identify==2.5.024 # via pre-commit25 nodeenv==1.6.026 # via pre-commit27 pep517==0.12.033 unmodified linesmodified:requirements/docs.txt+1 added-1 removed
19 unmodified lines20 idna==3.321 # via requests22 imagesize==1.3.023 # via sphinx24-jinja2==3.1.124+jinja2==3.1.225 # via sphinx26 markupsafe==2.1.127 # via jinja228 packaging==21.344 unmodified linesmodified:requirements/typing.txt+1 added-1 removed
3 unmodified lines4 # To update, run:5 #6 # pip-compile-multi7 #8-mypy==0.9428+mypy==0.9509 # via -r requirements/typing.in10 mypy-extensions==0.4.311 # via mypy12 tomli==2.0.13 unmodified linesmodified:src/click/core.py+3 added
2578 unmodified lines2579 2580 if self.is_flag:2581 raise TypeError("'count' is not valid with 'is_flag'.")2582 2583+ if self.multiple and self.is_flag:2584+ raise TypeError("'multiple' is not valid with 'is_flag', use 'count'.")2585+2586 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 linesmodified:src/click/decorators.py+4 added-4 removed
147 unmodified lines148 ...149 150 151 def command(152- name: t.Union[str, t.Callable, None] = None,152+ name: t.Union[str, t.Callable[..., t.Any], None] = None,153 cls: t.Optional[t.Type[Command]] = None,154 **attrs: t.Any,155 ) -> t.Union[Command, t.Callable[..., Command]]:156 r"""Creates a new :class:`Command` and uses the decorated function as24 unmodified lines181 The ``params`` argument can be used. Decorated params are182 appended to the end of the list.183 """184 185- func: t.Optional[t.Callable] = None185+ func: t.Optional[t.Callable[..., t.Any]] = None186 187 if callable(name):188 func = name189 name = None37 unmodified lines227 228 229 @t.overload230 def group(231- __func: t.Callable,231+ __func: t.Callable[..., t.Any],232 ) -> Group:233 ...234 235 5 unmodified lines241 ...242 243 244 def group(245- name: t.Union[str, t.Callable, None] = None, **attrs: t.Any245+ name: t.Union[str, t.Callable[..., t.Any], None] = None, **attrs: t.Any246 ) -> t.Union[Group, t.Callable[[F], Group]]:247 """Creates a new :class:`Group` with a function as callback. This248 works otherwise the same as :func:`command` just that the `cls`249 parameter is set to :class:`Group`.248 unmodified linesmodified:tests/test_options.py+18 added
902 unmodified lines903 ],904 )905 def test_is_bool_flag_is_correctly_set(option, expected):906 assert option.is_bool_flag is expected907+908+909+@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+)920+def test_invalid_flag_combinations(runner, kwargs, message):921+ with pytest.raises(TypeError) as e:922+ click.Option(["-a"], **kwargs)923+924+ assert message in str(e.value)modified:.pre-commit-config.yaml+1 added-1 removed
6 unmodified lines7891011111213141517 unmodified lines6 unmodified lines hooks: - id: pyupgrade args: ["--py37-plus"] - repo: https://github.com/asottile/reorder_python_imports rev: v3.0.1 rev: v3.1.0 hooks: - id: reorder-python-imports args: ["--application-directories", "src"] additional_dependencies: ["setuptools>60.9"]17 unmodified linesmodified:CHANGES.rst+12 added
4 unmodified lines5 6 Unreleased7 8 9+Version 8.1.310+-------------11+12+Released 2022-04-2813+14+- Use verbose form of ``typing.Callable`` for ``@command`` and15+ ``@group``. :issue:`2255`16+- Show error when attempting to create an option with17+ ``multiple=True, is_flag=True``. Use ``count`` instead.18+ :issue:`2246`19+20+21 Version 8.1.222 -------------23 24 Released 2022-03-311026 unmodified lines