bw2 / ConfigArgParse

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

allow for choices to be empty in config file but not on command line #257

Open mathisloevenich opened 2 years ago

mathisloevenich commented 2 years ago

A config file like:

values = []

resolves in: values=['']

it's unpleasent to have this empyt string. Instead it should be possible to just get an empty list.

mathisloevenich commented 2 years ago

If you work with choices, it will mess up the code. A workaround for this is to add an empty string to choices

choices.append([''])

mathisloevenich commented 2 years ago

If there is no particular reason for this behaviour it would be nice to fix this, even if it's not necessarily a bug.

mathisloevenich commented 2 years ago

With the new version 1.5.3 this is no longer working. It worked on 1.2.3

mathisloevenich commented 2 years ago

We can simply fix this with nargs="*", but obviously this would allow to have flags with no effects

carlfischerjba commented 2 years ago

This is an issue with environment variables too.

VALUES= python mytest.py will set the corresponding arg to [''], overriding the default value. This is generally not what we want.

If the env var VALUES is undefined it works as expected and the default value is used for that arg.