bw2 / ConfigArgParse

A drop-in replacement for argparse that allows options to also be set via config files and/or environment variables.
MIT License
728 stars 121 forks source link

Redo fix for nargs and append #186

Closed davistardif closed 4 years ago

davistardif commented 4 years ago

I am stupid and didn't actually fix the behavior for combining append and nargs in #178

I intended to allow actions of type append to accept lists when used with nargs=+,* or an int > 1 but I forgot to include the check that the action is append.

I also introduced a bug in #178 by not checking for nargs=None, which I apologize for, and am glad to see it was fixed quickly. This time I handle None correctly.

kamo-naoyuki commented 4 years ago

Please add test codes when PR. This modification causes a bug again.

AttributeError: 'NoneType' object has no attribute 'nargs'

https://github.com/bw2/ConfigArgParse/blob/6b34e073b6c69ae2fe12c3d4c308a9543d84bea5/configargparse.py#L744-L748

((isinstance(action, argparse._StoreAction) or isinstance(action, argparse._AppendAction)) and 
action.nargs is not None and
(action.nargs in ('+', '*')) or  
(isinstance(action.nargs, int) and action.nargs > 1))  # Here is evaluated even if action is None