Skip to content

argparse type=bool #6821

Open
Open
@Akuli

Description

@Akuli

When adding an argument with argparse.ArgumentParser.add_argument, it is tempting to pass type=bool to create an option that is specified without a value, such as --enable-foo. This doesn't work, and in fact creates a subtle bug: --enable-foo silently swallows the next argument, so a command like python3 program.py --enable-foo x y z will work but only leave y and z to be used as other arguments. https://stackoverflow.com/a/15008806

To prevent this, I think the best we can do is to add an overload that returns NoReturn when you pass in type=bool.

Metadata

Metadata

Assignees

No one assigned

    Labels

    stubs: false negativeType checkers do not report an error, but should

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions