Skip to content
Myr

Merge pull request #2217 from pallets/group-return

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

group without command passes return value to result callback

authored by David Lord · committed by GitHub · parents bf9da48, 7d3a871 · Browse files · 3 files+11 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

3 files+11 added−8 removed

  • tests:+4 added−4 removed
  • other:+7 added−4 removed

3 files+11 added−8 removed

modified:src/click/core.py+4 added-4 removed
1624 unmodified lines
16251626 if not ctx.protected_args:1627 if self.invoke_without_command:1628 # No subcommand was invoked, so the result callback is1629 # invoked with None for regular groups, or an empty list1630 # for chained groups.1629 # invoked with the group return value for regular1630 # groups, or an empty list for chained groups.1631 with ctx:1632 super().invoke(ctx)1633 return _process_result([] if self.chain else None)1632 rv = super().invoke(ctx)1633 return _process_result([] if self.chain else rv)1634 ctx.fail(_("Missing command."))16351636 # Fetch args back out1637 args = [*ctx.protected_args, *ctx.args]
1326 unmodified lines
modified:tests/test_chain.py+4 added-4 removed
83 unmodified lines
84 assert not result.exception85 assert result.output.splitlines() == ["bdist called 1", "sdist called 2"]868788@pytest.mark.parametrize(("chain", "expect"), [(False, "None"), (True, "[]")])88@pytest.mark.parametrize(("chain", "expect"), [(False, "1"), (True, "[]")])89def test_no_command_result_callback(runner, chain, expect):90 """When a group has ``invoke_without_command=True``, the result91 callback is always invoked. A regular group invokes it with92 ``None``, a chained group with ``[]``.92 its return value, a chained group with ``[]``.93 """9495 @click.group(invoke_without_command=True, chain=chain)96 def cli():97 pass97 return 19899 @cli.result_callback()100 def process_result(result):101 click.echo(str(result), nl=False)101 click.echo(result, nl=False)102103 result = runner.invoke(cli, [])104 assert result.output == expect105
140 unmodified lines
modified:CHANGES.rst+3 added
43 unmodified lines
44 params defined with decorators are appended to the passed params.45 :issue:`2131`.46- ``@command`` decorator is annotated as returning the correct type if47 a ``cls`` argument is used. :issue:`2211`48- A ``Group`` with ``invoke_without_command=True`` and ``chain=False``49 will invoke its result callback with the group function's return50 value. :issue:`2124`515253Version 8.0.454-------------
948 unmodified lines