Skip to content
Myr

invoke type casts default values

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 · parent 3dde6c5 · Browse files · 3 files+14 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+14 added−8 removed

  • tests:+9 added−7 removed
  • other:+5 added−1 removed

3 files+14 added−8 removed

modified:src/click/core.py+3 added-1 removed
737 unmodified lines
738 ctx = __self._make_sub_context(other_cmd)739740 for param in other_cmd.params:741 if param.name not in kwargs and param.expose_value:742 kwargs[param.name] = param.get_default(ctx) # type: ignore742 kwargs[param.name] = param.type_cast_value( # type: ignore743 ctx, param.get_default(ctx)744 )745746 # Track all kwargs as params, so that forward() will pass747 # them on in subsequent calls.748 ctx.params.update(kwargs)
2205 unmodified lines
modified:tests/test_commands.py+9 added-7 removed
244 unmodified lines
245 def cli(ctx):246 return ctx.invoke(other_cmd)247248 @click.command()249 @click.option("--foo", type=click.INT, default=42)249 @click.option("-a", type=click.INT, default=42)250 @click.option("-b", type=click.INT, default="15")251 @click.option("-c", multiple=True)252 @click.pass_context251 def other_cmd(ctx, foo):252 assert ctx.info_name == "other-cmd"253 click.echo(foo)253 def other_cmd(ctx, a, b, c):254 return ctx.info_name, a, b, c255255 result = runner.invoke(cli, [])256 assert not result.exception257 assert result.output == "42\n"256 result = runner.invoke(cli, standalone_mode=False)257 # invoke should type cast default values, str becomes int, empty258 # multiple should be empty tuple instead of None259 assert result.return_value == ("other-cmd", 42, 15, ())260261262def test_invoked_subcommand(runner):263 @click.group(invoke_without_command=True)
91 unmodified lines
modified:CHANGES.rst+2 added
7 unmodified lines
8- Fix issue with ``Path(resolve_path=True)`` type creating invalid9 paths. :issue:`2088`10- Importing ``readline`` does not cause the ``confirm()`` prompt to11 disappear when pressing backspace. :issue:`2092`12- Any default values injected by ``invoke()`` are cast to the13 corresponding parameter's type. :issue:`2089, 2090`141516Version 8.0.217-------------
917 unmodified lines