Skip to content

Commit

Permalink
Fix logic bug for list kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
evanunderscore committed Feb 8, 2016
1 parent 8c1d1ba commit 9c9b3ae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
18 changes: 10 additions & 8 deletions defopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,18 @@ def _populate_parser(func, parser):
type_ = _get_type(doc.params[name].type)
if param.kind == param.VAR_KEYWORD:
raise ValueError('**kwargs not supported')
if param.default == param.empty:
if type_.container:
assert type_.container == list
name_or_flag = '--' + name
kwargs['nargs'] = '*'
if type_.container:
assert type_.container == list
name_or_flag = '--' + name
kwargs['nargs'] = '*'
if param.default == param.empty:
kwargs['required'] = True
else:
name_or_flag = name
if param.kind == param.VAR_POSITIONAL:
kwargs['nargs'] = '*'
kwargs['default'] = param.default
elif param.default == param.empty:
name_or_flag = name
if param.kind == param.VAR_POSITIONAL:
kwargs['nargs'] = '*'
else:
name_or_flag = '--' + name
kwargs['default'] = param.default
Expand Down
10 changes: 10 additions & 0 deletions test_defopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ def main(foo):
self.assertEqual(foo, [1.1, 2.2])
defopt.run(['--foo', '1.1', '2.2'])

def test_list_kwarg(self):
@defopt.main
def main(foo=None):
"""Test function
:type foo: list[float]
"""
self.assertEqual(foo, [1.1, 2.2])
defopt.run(['--foo', '1.1', '2.2'])

def test_other_container(self):
@defopt.main
def main(foo):
Expand Down

0 comments on commit 9c9b3ae

Please sign in to comment.