Skip to content
Myr

Better error message for bad parameter default (#1805)

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

raise TypeError when multiple parameter has single default

authored by Saif Kazi · committed by GitHub · parent 4c7399e · Browse files · 3 files+25 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+25 added−1 removed

  • tests:+14 added−0 removed
  • other:+11 added−1 removed

3 files+25 added−1 removed

modified:src/click/core.py+9 added-1 removed
2009 unmodified lines
2010 def _convert(value, level):2011 if level == 0:2012 return self.type(value, self, ctx)20132014 return tuple(_convert(x, level - 1) for x in value)2014 try:2015 iter_value = iter(value)2016 except TypeError:2017 raise TypeError(2018 "Value for parameter with multiple = True or nargs > 1"2019 " should be an iterable."2020 )20212022 return tuple(_convert(x, level - 1) for x in iter_value)20232024 return _convert(value, (self.nargs != 1) + bool(self.multiple))20252026 def value_is_missing(self, value):2027 if value is None:
585 unmodified lines
modified:tests/test_options.py+14 added
115 unmodified lines
116 assert result.exception117 assert "Error: Missing option '-m' / '--message'." in result.output118119120def test_multiple_bad_default(runner):121 @click.command()122 @click.option("--flags", multiple=True, default=False)123 def cli(flags):124 pass125126 result = runner.invoke(cli, [])127 assert result.exception128 assert (129 "Value for parameter with multiple = True or nargs > 1 should be an iterable."130 in result.exception.args131 )132133134def test_empty_envvar(runner):135 @click.command()136 @click.option("--mypath", type=click.Path(exists=True), envvar="MYPATH")137 def cli(mypath):
600 unmodified lines
modified:CHANGES.rst+2 added
180 unmodified lines
181- Progress bar ``item_show_func`` shows the current item, not the182 previous item. :issue:`1353`183- The ``Path`` param type can be passed ``path_type=pathlib.Path`` to184 return a path object instead of a string. :issue:`405`185- ``TypeError`` is raised when parameter with ``multiple=True`` or186 ``nargs > 1`` has non-iterable default. :issue:`1749`187188189Version 7.1.2190-------------
635 unmodified lines