Skip to content
Myr

move command cls setting after assert check

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

authored by Eric Williamson · committed by David Lord · parent e4066e1 · Browse files · 3 files+25 added−3 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+25 added−3 removed

  • tests:+20 added−0 removed
  • other:+5 added−3 removed

3 files+25 added−3 removed

modified:src/click/core.py+3 added-3 removed
1869 unmodified lines
1870 Added the :attr:`command_class` attribute.1871 """1872 from .decorators import command18731874 if self.command_class and kwargs.get("cls") is None:1875 kwargs["cls"] = self.command_class18761874 func: t.Optional[t.Callable[..., t.Any]] = None18751876 if args and callable(args[0]):1877 assert (
1 unmodified line
1879 ), "Use 'command(**kwargs)(callable)' to provide arguments."1880 (func,) = args1881 args = ()18821883 if self.command_class and kwargs.get("cls") is None:1884 kwargs["cls"] = self.command_class18851886 def decorator(f: t.Callable[..., t.Any]) -> Command:1887 cmd: Command = command(*args, **kwargs)(f)1888 self.add_command(cmd)1889 return cmd
1151 unmodified lines
modified:tests/test_command_decorators.py+20 added
9 unmodified lines
10 assert result.exception is None11 assert result.output == "hello\n"121314def test_custom_command_no_parens(runner):15 class CustomCommand(click.Command):16 pass1718 class CustomGroup(click.Group):19 command_class = CustomCommand2021 @click.group(cls=CustomGroup)22 def grp():23 pass2425 @grp.command26 def cli():27 click.echo("hello custom command class")2829 result = runner.invoke(cli)30 assert result.exception is None31 assert result.output == "hello custom command class\n"323334def test_group_no_parens(runner):35 @click.group36 def grp():37 click.echo("grp1")
34 unmodified lines
modified:CHANGES.rst+2 added
18 unmodified lines
19- Avoid showing empty lines if command help text is empty. :issue:`2368`20- ZSH completion script works when loaded from ``fpath``. :issue:`2344`.21- ``EOFError`` and ``KeyboardInterrupt`` tracebacks are not suppressed when22 ``standalone_mode`` is disabled. :issue:`2380`23- ``@group.command`` does not fail if the group was created with a custom24 ``command_class``. :issue:`2416`252627Version 8.1.328-------------
1040 unmodified lines