Skip to content
Myr

Disallow nargs=-1 with a default set.

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

authored by Armin Ronacher · committed by Armin Ronacher · parent 5620b05 · Browse files · 3 files+16 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+16 added−0 removed

  • tests:+12 added−0 removed
  • other:+4 added−0 removed

3 files+16 added−0 removed

modified:click/core.py+3 added
1672 unmodified lines
1673 required = False1674 else:1675 required = attrs.get('nargs', 1) > 01676 Parameter.__init__(self, param_decls, required=required, **attrs)1677 if self.default is not None and self.nargs < 0:1678 raise TypeError('nargs=-1 in combination with a default value '1679 'is not supported.')16801681 @property1682 def human_readable_name(self):1683 if self.metavar is not None:
38 unmodified lines
modified:tests/test_arguments.py+12 added
16 unmodified lines
17 'dst=dir',18 ]192021def test_nargs_default(runner):22 try:23 @click.command()24 @click.argument('src', nargs=-1, default=42)25 def copy(src):26 pass27 except TypeError as e:28 assert 'nargs=-1' in str(e)29 else:30 assert False313233def test_nargs_tup(runner):34 @click.command()35 @click.argument('name', nargs=1)36 @click.argument('point', nargs=2, type=click.INT)
222 unmodified lines
modified:CHANGES+1 added
11 unmodified lines
12 actually change.13- Actively reject multi commands within chained multi commands. This14 cannot be supported with the current setup of how the invocation for15 subcommands works.16- Explicitly disallow nargs=-1 with a set default.1718Version 5.119-----------20
251 unmodified lines