Skip to content

Clarify argparse action documentation #141963

@moshekaplan

Description

@moshekaplan

Documentation

The documentation for several of argparse's actions could be improved to be shorter and clearer.

For specific examples:

'store_true' and 'store_false' - These are special cases of 'store_const' used for storing the values True and False respectively. In addition, they create default values of False and True respectively:

The In addition part is clunky.

'append_const' - This stores a list, and appends the value specified by the const keyword argument to the list; note that the const keyword argument defaults to None. The 'append_const' action is typically useful when multiple arguments need to store constants to the same list. For example:

This could be shorter.

'extend' - This stores a list and appends each item from the multi-value argument list to it. The 'extend' action is typically used with the nargs keyword argument value '+' or '*'. Note that when nargs is None (the default) or '?', each character of the argument string will be appended to the list. Example usage:

This sentence feels convoluted

'count' - This counts the number of times a keyword argument occurs. For example, this is useful for increasing verbosity levels:

The argument parsed by argparse is not specifically a keyword argument; this seems like a copy-paste error for the times it's referring to add_argument's args, as opposed to an argument parsed by argparse.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Doc issues

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions