Revert "Fix choices validation with unannotated args"

This reverts commit 12061b8bb1.
This commit is contained in:
Florian Bruhin 2016-08-23 23:34:02 +02:00
parent e4008c4e08
commit 445d287955
3 changed files with 4 additions and 16 deletions

View File

@ -119,7 +119,7 @@ def type_conv(param, typ, value, *, str_choices=None):
if utils.is_enum(typ): if utils.is_enum(typ):
_check_choices(param, value, [arg_name(e.name) for e in typ]) _check_choices(param, value, [arg_name(e.name) for e in typ])
return typ[value.replace('-', '_')] return typ[value.replace('-', '_')]
elif typ in [str, None]: elif typ is str:
if str_choices is not None: if str_choices is not None:
_check_choices(param, value, str_choices) _check_choices(param, value, str_choices)
return value return value

View File

@ -422,9 +422,11 @@ class Command:
choices = self.get_arg_info(param).choices choices = self.get_arg_info(param).choices
value = argparser.multitype_conv(param, types, value, value = argparser.multitype_conv(param, types, value,
str_choices=choices) str_choices=choices)
elif typ in [str, None]: elif typ is str:
choices = self.get_arg_info(param).choices choices = self.get_arg_info(param).choices
value = argparser.type_conv(param, typ, value, str_choices=choices) value = argparser.type_conv(param, typ, value, str_choices=choices)
elif typ is None:
pass
elif typ is bool: # no type conversion for flags elif typ is bool: # no type conversion for flags
assert isinstance(value, bool) assert isinstance(value, bool)
else: else:

View File

@ -295,20 +295,6 @@ class TestRegister:
else: else:
assert cmd._get_call_args(win_id=0) == ([expected], {}) assert cmd._get_call_args(win_id=0) == ([expected], {})
def test_choices_no_annotation(self):
# https://github.com/The-Compiler/qutebrowser/issues/1871
@cmdutils.register()
@cmdutils.argument('arg', choices=['foo', 'bar'])
def fun(arg):
"""Blah."""
pass
cmd = cmdutils.cmd_dict['fun']
cmd.namespace = cmd.parser.parse_args(['fish'])
with pytest.raises(cmdexc.ArgumentTypeError):
cmd._get_call_args(win_id=0)
def test_pos_arg_info(self): def test_pos_arg_info(self):
@cmdutils.register() @cmdutils.register()
@cmdutils.argument('foo', choices=('a', 'b')) @cmdutils.argument('foo', choices=('a', 'b'))