File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -182,6 +182,8 @@ Unreleased
182182 previous item. :issue: `1353 `
183183- The ``Path `` param type can be passed ``path_type=pathlib.Path `` to
184184 return a path object instead of a string. :issue: `405 `
185+ - ``TypeError `` is raised when parameter with ``multiple=True `` or
186+ ``nargs > 1 `` has non-iterable default. :issue: `1749 `
185187
186188
187189Version 7.1.2
Original file line number Diff line number Diff line change @@ -2011,7 +2011,15 @@ def _convert(value, level):
20112011 if level == 0 :
20122012 return self .type (value , self , ctx )
20132013
2014- 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+ )
2021+
2022+ return tuple (_convert (x , level - 1 ) for x in iter_value )
20152023
20162024 return _convert (value , (self .nargs != 1 ) + bool (self .multiple ))
20172025
Original file line number Diff line number Diff line change @@ -117,6 +117,20 @@ def cli(message):
117117 assert "Error: Missing option '-m' / '--message'." in result .output
118118
119119
120+ def test_multiple_bad_default (runner ):
121+ @click .command ()
122+ @click .option ("--flags" , multiple = True , default = False )
123+ def cli (flags ):
124+ pass
125+
126+ result = runner .invoke (cli , [])
127+ assert result .exception
128+ assert (
129+ "Value for parameter with multiple = True or nargs > 1 should be an iterable."
130+ in result .exception .args
131+ )
132+
133+
120134def test_empty_envvar (runner ):
121135 @click .command ()
122136 @click .option ("--mypath" , type = click .Path (exists = True ), envvar = "MYPATH" )
You can’t perform that action at this time.
0 commit comments