Expected Behavior
When creating a parameter with multiple=True and default=(1, 2), the type should be detected as INT. Calling get_default should return the default.
import click
opt = click.Option(["-c"], multiple=True, default=(1, 2))
print(opt.type)
ctx = click.Context(click.Command("test"))
value = opt.get_default(ctx)
print(value)
Actual Behavior
The type is detected as Tuple(INT, INT). This then causes problems when get_default calls type_cast_value.
Traceback (most recent call last):
File "/home/david/Projects/click/example.py", line 5, in <module>
value = opt.get_default(ctx)
File "/home/david/Projects/click/src/click/core.py", line 2248, in get_default
return super().get_default(ctx, call=call)
File "/home/david/Projects/click/src/click/core.py", line 1808, in get_default
return self.type_cast_value(ctx, value)
File "/home/david/Projects/click/src/click/core.py", line 1840, in type_cast_value
return tuple(self.type(x or (), self, ctx) for x in value or ())
File "/home/david/Projects/click/src/click/core.py", line 1840, in <genexpr>
return tuple(self.type(x or (), self, ctx) for x in value or ())
File "/home/david/Projects/click/src/click/types.py", line 62, in __call__
return self.convert(value, param, ctx)
File "/home/david/Projects/click/src/click/types.py", line 749, in convert
if len(value) != len(self.types):
TypeError: object of type 'int' has no len()
It fails in a different way if default=("a", "b").
Traceback (most recent call last):
File "/home/david/Projects/click/example.py", line 5, in <module>
value = opt.get_default(ctx)
File "/home/david/Projects/click/src/click/core.py", line 2248, in get_default
return super().get_default(ctx, call=call)
File "/home/david/Projects/click/src/click/core.py", line 1808, in get_default
return self.type_cast_value(ctx, value)
File "/home/david/Projects/click/src/click/core.py", line 1840, in type_cast_value
return tuple(self.type(x or (), self, ctx) for x in value or ())
File "/home/david/Projects/click/src/click/core.py", line 1840, in <genexpr>
return tuple(self.type(x or (), self, ctx) for x in value or ())
File "/home/david/Projects/click/src/click/types.py", line 62, in __call__
return self.convert(value, param, ctx)
File "/home/david/Projects/click/src/click/types.py", line 750, in convert
raise TypeError(
TypeError: It would appear that nargs is set to conflict with the composite type arity.
Environment
- Python version: 3.8.5
- Click version: 8.0.0.dev0
Expected Behavior
When creating a parameter with
multiple=Trueanddefault=(1, 2), the type should be detected asINT. Callingget_defaultshould return the default.Actual Behavior
The type is detected as
Tuple(INT, INT). This then causes problems whenget_defaultcallstype_cast_value.It fails in a different way if
default=("a", "b").Environment