Conversation
…efault The 'append' bullet says that a non-empty list default is kept and that command-line values land after it. 'extend' works the same way for an option, but the docs say nothing about it, which is the confusion reported in pythongh-110131. The sentence is scoped to the option deliberately. For a positional with nargs='*' or '?' and no command-line values, _get_values hands the default back as the parsed value while the same default is already in the namespace, so the action applies it twice and extend(default=['X']) yields ['X', 'X']. The unqualified wording would be wrong there.
TestOptionalsActionAppendWithDefault covers this for 'append'; there was no equivalent for 'extend', so nothing pinned the behavior the docs now describe. The coverage is limited to an option, matching the scope of the new sentence.
…end docs Before pythonGH-131389 the bullet read "the default elements will be present in the parsed value for the option". That copyedit rewrote the sentence and added an example, and the qualifier went with it, which left the bullet claiming something that does not hold for positionals: append with nargs='*' or '?' and default=['X'] gives ['X', ['X']] on empty input, because the default is applied twice. pythongh-110131 is filed against both 'append' and 'extend', so put the scope back rather than leave the two bullets disagreeing about it.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Documentation build overview
7 files changed ·
|
There was a problem hiding this comment.
We probably want to update this to show the behaviour with a non-empty default, since that's what we're documenting here.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
Both done. Test is gone, and the Docs only now. |
|
Can we keep it to one example for extend? I think the new one you've added covers our bases and we can remove the old one. |
|
Done, one example now. I folded the repeated |
Closes #110131.
@serhiy-storchaka already settled what this is:
So this only touches the docs. Two things were off.
The
appendsection explains that a non-empty default is kept and command-line values are appended after it, but it says "the parsed value" without saying whose, which reads as if it were about the list being appended to rather than the option's final value. That now says "the parsed value for the option".The
extendsection had no such note at all, even though it behaves identically:Same shape as
append, and the surprise in the issue is the same one, so the same note now appears there.A test pins both, since the whole point is that the documented behaviour is the real one and nobody had written it down.
./python.exe -m test test_argparseis 1,978 passing. Docs plus one test, no behaviour change, so no news entry.