Skip to content

Argparse: "default" interacts incorrectly/non-intuitively with action="count" #127296

@MJKirk

Description

@MJKirk

Very similar to issue #110131 - the documentation is not clear on how default and count interact.

Consider

parser = argparse.ArgumentParser()
parser.add_argument('--verbose', '-v', action='count', default=3)
parser.parse_args(['-v'])

My intuition, and how I read the documentation, is that you should end up with verbose=1, but actually you get verbose=4.
I haven't checked the source code, but I assume under the hood something similar to append/extend is happening.

My take is that it would be better for default to really act as a default, and get overwritten rather than added to by the passed arguments. But if not, the documentation should be changed to something similar to what is written for action="append".

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