This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jol
Recipients eric.smith, jol, paul.j3
Date 2019-07-06.15:58:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1562428695.47.0.794953143365.issue37510@roundup.psfhosted.org>
In-reply-to
Content
> There are earlier bug/issues about the '--'.

Yes, there are:

https://bugs.python.org/issue9571
https://bugs.python.org/issue22223
https://bugs.python.org/issue14364

But this one seems separate. Though they're related, they don't seem like duplicates, so that's why I thought I'd make this one.

> Also look at the parser code itself.  Keep in mind that parsing is done in two passes - once to identify flags versus arguments ('O/A') and then to allocate strings to arguments. I don't recall when '--' is being handled, possibly in both.

I'm not sure what your point is here. I did take a quick look at the code, yesterday. I think the identification part you mention is done right. It marks 'O/A' as you mention. Then, when it sees "--", it marks it "-", and the rest of the arguments are marked as "A".

I didn't look at the start of the code of the second pass or how it is concretely linked to the first pass. However, I did see that in the example I gave, _get_values() in argparse.py gets called twice (apparently once per argument group as determined by nargs, I guess) to remove the "--" present in arg_strings. The first time, arg_strings is ["foo", "--"] and the second time it's ["bar", "--", "baz", "--", "zap"].

So, that's what happens, and where part of the fix should probably be. I don't think the removal of "--" should happen in a function that gets called multiple times. Though I didn't spend the time to see where the code should be positioned, I can only imagine the correct behavior would be to remove the argument marked as "-" by the first pass mentioned.

I didn't mention this yesterday, because I figured there wouldn't be much value in sharing incomplete research like this, as opposed to a patch. I didn't want to influence the work of whoever chose to invest time in this for a proper fix.
History
Date User Action Args
2019-07-06 15:58:15jolsetrecipients: + jol, eric.smith, paul.j3
2019-07-06 15:58:15jolsetmessageid: <1562428695.47.0.794953143365.issue37510@roundup.psfhosted.org>
2019-07-06 15:58:15jollinkissue37510 messages
2019-07-06 15:58:14jolcreate