make sure keyword-only arguments have a default
Fixes #1872. This prevents inspect.Parameter.empty from slipping through to the command.
This commit is contained in:
parent
8bdcd49626
commit
0ef5d338bd
@ -246,6 +246,10 @@ class Command:
|
||||
continue
|
||||
if self._inspect_special_param(param):
|
||||
continue
|
||||
if (param.kind == inspect.Parameter.KEYWORD_ONLY and
|
||||
param.default is inspect.Parameter.empty):
|
||||
raise TypeError("{}: handler has keyword only argument "
|
||||
"without default!".format(self.name))
|
||||
typ = self._get_type(param)
|
||||
is_bool = typ is bool
|
||||
kwargs = self._param_to_argparse_kwargs(param, is_bool)
|
||||
|
@ -349,6 +349,24 @@ class TestRegister:
|
||||
with pytest.raises(IndexError):
|
||||
cmd.get_pos_arg_info(2)
|
||||
|
||||
def test_keyword_only_without_default(self):
|
||||
# https://github.com/The-Compiler/qutebrowser/issues/1872
|
||||
def fun(*, target):
|
||||
"""Blah."""
|
||||
pass
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
fun = cmdutils.register()(fun)
|
||||
|
||||
def test_typed_keyword_only_without_default(self):
|
||||
# https://github.com/The-Compiler/qutebrowser/issues/1872
|
||||
def fun(*, target: int):
|
||||
"""Blah."""
|
||||
pass
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
fun = cmdutils.register()(fun)
|
||||
|
||||
|
||||
class TestArgument:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user