Skip to content

Clarify argparse's append action #139067

@moshekaplan

Description

@moshekaplan

Documentation

The documentation for argparse's append action when a default value is provided is unclear

Currently the docs state:

'append' - This stores a list, and appends each argument value to the list. It is useful to allow an option to be specified multiple times. If the default value is non-empty, the default elements will be present in the parsed value for the option, with any values from the command line appended after those default values. Example usage:

parser = argparse.ArgumentParser()
parser.add_argument('--foo', action='append')
parser.parse_args('--foo 1 --foo 2'.split())
Namespace(foo=['1', '2'])

However, this documentation does not specify that the default needs to be a list, and cannot be a single value. While this may be obvious in hindsight, a short example would entirely remove this source of confusion.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    No status

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions