Skip to content
Myr

argument with nargs=-1 and envvar prefers command line value

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

authored by Marc Schmitzer · committed by David Lord · parent 6c9179c · Browse files · 3 files+18 added−1 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+18 added−1 removed

  • tests:+13 added−0 removed
  • other:+5 added−1 removed

3 files+18 added−1 removed

modified:src/click/parser.py+3 added-1 removed
231 unmodified lines
232 name=self.dest, nargs=self.nargs233 )234 )235236 if self.nargs == -1 and self.obj.envvar is not None:236 if self.nargs == -1 and self.obj.envvar is not None and value == ():237 # Replace empty tuple with None so that a value from the238 # environment may be tried.239 value = None240241 state.opts[self.dest] = value # type: ignore242 state.order.append(self.obj)
287 unmodified lines
modified:tests/test_arguments.py+13 added
192 unmodified lines
193 else:194 assert result.return_value == expect195196197def test_nargs_envvar_only_if_values_empty(runner):198 @click.command()199 @click.argument("arg", envvar="X", nargs=-1)200 def cli(arg):201 return arg202203 result = runner.invoke(cli, ["a", "b"], standalone_mode=False)204 assert result.return_value == ("a", "b")205206 result = runner.invoke(cli, env={"X": "a"}, standalone_mode=False)207 assert result.return_value == ("a",)208209210def test_empty_nargs(runner):211 @click.command()212 @click.argument("arg", nargs=-1)213 def cmd(arg):
166 unmodified lines
modified:CHANGES.rst+2 added
12 unmodified lines
13- Fix type checking for iterating over ``ProgressBar`` object.14 :issue:`1892`15- The ``importlib_metadata`` backport package is installed on Python <16 3.8. :issue:`1889`17- Arguments with ``nargs=-1`` only use env var value if no command18 line values are given. :issue:`1903`192021Version 8.0.022-------------
854 unmodified lines