Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiline lists are not parsed in config files the way I'd expect #299

Open
agyoungs opened this issue Oct 31, 2024 · 0 comments
Open

Multiline lists are not parsed in config files the way I'd expect #299

agyoungs opened this issue Oct 31, 2024 · 0 comments

Comments

@agyoungs
Copy link

agyoungs commented Oct 31, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant