Skip to content
Myr

Error on nargs=-1 for options. This fixes #222

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 c2c2bac · Browse files · 4 files+17 added−2 removed
This commit

State

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

Diff stats

4 files+17 added−2 removed

  • tests:+14 added−2 removed
  • other:+3 added−0 removed

4 files+17 added−2 removed

modified:click/core.py+2 added
1403 unmodified lines
1404 self.show_default = show_default14051406 # Sanity check for stuff we don't support1407 if __debug__:1408 if self.nargs < 0:1409 raise TypeError('Options cannot have nargs < 0')1410 if self.prompt and self.is_flag and not self.is_bool_flag:1411 raise TypeError('Cannot prompt for flags that are not bools.')1412 if not self.is_bool_flag and self.secondary_opts:1413 raise TypeError('Got secondary option for non boolean flag.')
221 unmodified lines
modified:tests/test_arguments.py+2 added-2 removed
104 unmodified lines
105106107def test_nargs_envvar(runner):108 @click.command()109 @click.option('--arg', nargs=-1)109 @click.option('--arg', nargs=2)110 def cmd(arg):111 click.echo('|'.join(arg))112113 result = runner.invoke(cmd, [], auto_envvar_prefix='TEST',
1 unmodified line
115 assert not result.exception116 assert result.output == 'foo|bar\n'117118 @click.command()119 @click.option('--arg', envvar='X', nargs=-1)119 @click.option('--arg', envvar='X', nargs=2)120 def cmd(arg):121 click.echo('|'.join(arg))122123 result = runner.invoke(cmd, [], env={'X': 'foo bar'})
68 unmodified lines
modified:tests/test_options.py+12 added
32 unmodified lines
33 else:34 assert False, 'Expected a type error because of an invalid option.'353637def test_invalid_nargs(runner):38 try:39 @click.command()40 @click.option('--foo', nargs=-1)41 def cli(foo):42 pass43 except TypeError as e:44 assert 'Options cannot have nargs < 0' in str(e)45 else:46 assert False, 'Expected a type error because of an invalid option.'474849def test_counting(runner):50 @click.command()51 @click.option('-v', count=True, help='Verbosity',52 type=click.IntRange(0, 3))
226 unmodified lines
modified:CHANGES+1 added
23 unmodified lines
24- Added support for writing prompts to stderr.25- Fix a bug when showing the default for multiple arguments.26- Added support for custom subclasses to `option` and `argument`.27- Fix bug in ``clear()`` on Windows when colorama is installed.28- Reject ``nargs=-1`` for options properly. Options cannot be variadic.2930Version 3.331-----------32
176 unmodified lines