From 8680dbec72f94d17f38b5a89ea06cdf2e60ee208 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Fri, 14 Sep 2018 22:53:41 -0700 Subject: [PATCH] Fix nargs --- julia/pseudo_python_cli.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/julia/pseudo_python_cli.py b/julia/pseudo_python_cli.py index 2011f340..1258d9eb 100644 --- a/julia/pseudo_python_cli.py +++ b/julia/pseudo_python_cli.py @@ -141,9 +141,7 @@ def _add_argument_impl(self, name, alt, dest=None, nargs=None, action=None, raise TypeError("`nargs` and `action` are mutually exclusive") if action == "store_true": nargs = 0 - if nargs is None: - nargs = 1 - assert isinstance(nargs, int) + assert nargs is None or isinstance(nargs, int) assert action in (None, "store_true") assert dest not in self._dests @@ -199,7 +197,10 @@ def _parse_until_terminal(self, ns, args_iter): .format(", ".join(res.option.argdest.names))) seen.add(dest) - while len(res.values) < res.option.nargs: + num_args = res.option.nargs + if num_args is None: + num_args = 1 + while len(res.values) < num_args: try: res.values.append(next(args_iter)) except StopIteration: @@ -209,7 +210,7 @@ def _parse_until_terminal(self, ns, args_iter): setattr(ns, dest, True) else: value = res.values - if res.option.nargs == 1: + if res.option.nargs is None: value, = value setattr(ns, dest, value) @@ -233,7 +234,7 @@ def _find_matches(self, arg): if opt.is_long and arg[len(opt.name)] == "=": return [Result(opt, [arg[len(opt.name) + 1:]])] elif not opt.is_long: - if opt.nargs > 0: + if opt.nargs != 0: return [Result(opt, [arg[len(opt.name):]])] else: results = [Result(opt, [])]