Merge branch 'Kingdread-kwonly-default-fix'
This commit is contained in:
commit
8b7c457802
@ -246,6 +246,11 @@ 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 "
|
||||
"{!r} without default!".format(self.name,
|
||||
param.name))
|
||||
typ = self._get_type(param)
|
||||
is_bool = typ is bool
|
||||
kwargs = self._param_to_argparse_kwargs(param, is_bool)
|
||||
|
@ -324,7 +324,7 @@ class TestRegister:
|
||||
# https://github.com/The-Compiler/qutebrowser/issues/1871
|
||||
@cmdutils.register()
|
||||
@cmdutils.argument('arg', choices=['foo', 'bar'])
|
||||
def fun(*, arg):
|
||||
def fun(*, arg='foo'):
|
||||
"""Blah."""
|
||||
pass
|
||||
|
||||
@ -349,6 +349,32 @@ 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) as excinfo:
|
||||
fun = cmdutils.register()(fun)
|
||||
|
||||
expected = ("fun: handler has keyword only argument 'target' without "
|
||||
"default!")
|
||||
assert str(excinfo.value) == expected
|
||||
|
||||
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) as excinfo:
|
||||
fun = cmdutils.register()(fun)
|
||||
|
||||
expected = ("fun: handler has keyword only argument 'target' without "
|
||||
"default!")
|
||||
assert str(excinfo.value) == expected
|
||||
|
||||
|
||||
class TestArgument:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user