You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Argparse: "default" interacts incorrectly/non-intuitively with action="count" #127296
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".
I'm not sure that's a great assumption. I think of "-v" in this case as "increment the current value by one", and here the current value initially would be the default.
In any event, this can't be changed due to backward compatibility, although I guess we could add another option to control this behavior. Something along the lines of "initial value to be used if this option ever processed", and you'd use 0 in this case.
Good job finding #110131! I agree it's basically the same, except for action="count".
Behavior same as sum([1], 3) == 4, with parameter names default and start being synonyms. Perhaps add "The count starts with the default when the latter is not 0" . Note that start can be negative (same for default?), so that the result is the deficit or surplus with respect to start. I don't know if this is a sensible usage for argparse.
I can see for backwards compatibility reasons the argument name default cannot be changed, but it seems something like initial would convey the behaviour better.
"The count starts with the default when the latter is not 0"
Something like this would make the documentation clearer 👍
Activity
[scripts] Add environment variable to control verbosity
[scripts] Add environment variable to control verbosity
ericvsmith commentedon Nov 26, 2024
I'm not sure that's a great assumption. I think of "-v" in this case as "increment the current value by one", and here the current value initially would be the default.
In any event, this can't be changed due to backward compatibility, although I guess we could add another option to control this behavior. Something along the lines of "initial value to be used if this option ever processed", and you'd use 0 in this case.
Good job finding #110131! I agree it's basically the same, except for
action="count".terryjreedy commentedon Nov 26, 2024
Behavior same as
sum([1], 3) == 4, with parameter namesdefaultandstartbeing synonyms. Perhaps add "The count starts with the default when the latter is not 0" . Note that start can be negative (same for default?), so that the result is the deficit or surplus with respect to start. I don't know if this is a sensible usage for argparse.MJKirk commentedon Nov 27, 2024
I can see for backwards compatibility reasons the argument name
defaultcannot be changed, but it seems something likeinitialwould convey the behaviour better.Something like this would make the documentation clearer 👍
rhettinger commentedon Nov 27, 2024
+1 for this edit.
ericvsmith commentedon Nov 29, 2024
Agreed. And if we do this here, we should also do it for #110131.
Merge branch 'main' into pythongh-127296-argparse-count-default
gh-127296: Document that argparse count action starts from a non-zero…
[3.14] gh-127296: Document that argparse count action starts from a n…
[3.13] gh-127296: Document that argparse count action starts from a n…
[3.15] gh-127296: Document that argparse count action starts from a n…
pythongh-127296: Document that argparse count action starts from a no…