Skip to content

Commit

Permalink
fix: variable arg handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jnoortheen committed Apr 17, 2020
1 parent c581cb9 commit aaa7109
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
9 changes: 7 additions & 2 deletions arger/parser/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@

def get_nargs(typ: Any) -> Tuple[Any, Union[int, str]]:
inner = unpack_type(typ)
if is_tuple(typ) and get_inner_args(typ):
if (
is_tuple(typ)
and typ != tuple
and not isinstance(typ, (VarKw, VarArg))
and get_inner_args(typ)
):
args = get_inner_args(typ)
inner = inner if len(set(args)) == 1 else str
return inner, '+' if (... in args) else len(args)
Expand All @@ -30,7 +35,7 @@ def __init__(self, *args, **kwargs):
self.orig_type = typ
if typ is not UNDEFINED:
origin = get_origin(typ)
if is_iterable(origin) or isinstance(typ, (VarArg, VarKw)):
if is_iterable(origin):
origin, kwargs["nargs"] = get_nargs(typ)

if is_enum(origin):
Expand Down
8 changes: 5 additions & 3 deletions arger/parser/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ def get_param(param):
def create_option(param: Param, default, option_generator):
if isinstance(default, Argument):
option = default
default.update_flags(param.name)
default.update(param.type)
option.update_flags(param.name)
if 'type' not in option.kwargs:
option.update(param.type)
elif isinstance(default, Option):
option = default
option.update_flags(param.name, option_generator)
option.update(param.type)
if 'type' not in option.kwargs:
option.update(param.type)
else:
option = Option(help=param.help)
option.update_flags(param.name, option_generator)
Expand Down
2 changes: 1 addition & 1 deletion arger/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class VarArg:
__args__ = ()

def __init__(self, tp):
self.__args__ = (tp,)
self.__args__ = (tp, ...)

def __repr__(self):
tp = self.__args__[0]
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ def pytest_generate_tests(metafunc):
cmds.pop(0)
cmds.pop(0)
cmds.insert(0, py_file.name)
idlist.append("-".join(cmds))
idlist.append("-".join(cmds).replace('.', ''))
argvalues.append((py_file, cmd, output))
metafunc.parametrize("pyfile, cmd, expected", argvalues, ids=idlist)

0 comments on commit aaa7109

Please sign in to comment.