@@ -141,9 +141,7 @@ def _add_argument_impl(self, name, alt, dest=None, nargs=None, action=None,
141
141
raise TypeError ("`nargs` and `action` are mutually exclusive" )
142
142
if action == "store_true" :
143
143
nargs = 0
144
- if nargs is None :
145
- nargs = 1
146
- assert isinstance (nargs , int )
144
+ assert nargs is None or isinstance (nargs , int )
147
145
assert action in (None , "store_true" )
148
146
149
147
assert dest not in self ._dests
@@ -199,7 +197,10 @@ def _parse_until_terminal(self, ns, args_iter):
199
197
.format (", " .join (res .option .argdest .names )))
200
198
seen .add (dest )
201
199
202
- while len (res .values ) < res .option .nargs :
200
+ num_args = res .option .nargs
201
+ if num_args is None :
202
+ num_args = 1
203
+ while len (res .values ) < num_args :
203
204
try :
204
205
res .values .append (next (args_iter ))
205
206
except StopIteration :
@@ -209,7 +210,7 @@ def _parse_until_terminal(self, ns, args_iter):
209
210
setattr (ns , dest , True )
210
211
else :
211
212
value = res .values
212
- if res .option .nargs == 1 :
213
+ if res .option .nargs is None :
213
214
value , = value
214
215
setattr (ns , dest , value )
215
216
@@ -233,7 +234,7 @@ def _find_matches(self, arg):
233
234
if opt .is_long and arg [len (opt .name )] == "=" :
234
235
return [Result (opt , [arg [len (opt .name ) + 1 :]])]
235
236
elif not opt .is_long :
236
- if opt .nargs > 0 :
237
+ if opt .nargs != 0 :
237
238
return [Result (opt , [arg [len (opt .name ):]])]
238
239
else :
239
240
results = [Result (opt , [])]
0 commit comments