ConfigArgParse
ConfigArgParse copied to clipboard
Multiline lists are not parsed in config files the way I'd expect
Consider the program (test.py):
#! /usr/bin/env python3
import configargparse
def main():
parser = configargparse.ArgumentParser()
parser.add_argument('-c', '--config', is_config_file=True)
parser.add_argument('--list', nargs='+')
args = parser.parse_args()
print(args)
if __name__ == "__main__":
main()
With the config file (test.toml):
list = [
1,
2,
3,
]
When running this you get an error. Presumably because the config parser is trying to allow for many different config formats at once.
> ./test.py -c test.toml
usage: test.py [-h] [-c CONFIG] [--list LIST [LIST ...]]
test.py: error: unrecognized arguments: --1,=true --2,=true --3,=true --]=true
If you change the list to one line instead, it works. With the caveat that the trailing , causes issues.
list = [1, 2, 3, ]
> ./test.py -c test.toml
Namespace(config='test.toml', list=['1', '2', '3', ''])
I know you can specify different config parsers. I haven't tried doing that, but if that works, would it not be a good idea to change the config parser to use a the correct config file parser based on known file types and revert to the default one if it doesn't recognize the file type?