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:
Daniel Schadt 2016-09-15 15:44:33 +02:00
parent 8bdcd49626
commit 0ef5d338bd
2 changed files with 22 additions and 0 deletions

View File

@ -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)

View File

@ -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: