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 paul.j3
Recipients Max Rothman, martin.panter, paul.j3, r.david.murray
Date 2017-03-12.17:45:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1489340704.53.0.19495012093.issue29715@psf.upfronthosting.co.za>
In-reply-to
Content
I think that this string falls through to the last case in 'parser._parse_optional' (the first parsing loop)

        # it was meant to be an optional but there is no such option
        # in this parser (though it might be a valid option in a subparser)
        return None, arg_string, None

It has the format of a optional flag, not a positional argument.  If preceded by '--' it gets classed as argument.

(In the second, main, parsing loop) Since it doesn't match any defined Actions it gets put in the list of 'extras' (as returned by 'parse_known_args').  But the parser also runs a check on required arguments, and finds the positional, 'first', was not filled.  So that's the error that's raised.

For example if I provide another string that fills the positional:

    In [5]: parser.parse_known_args(['-_','other'])
    Out[5]: (Namespace(first='other'), ['-_'])

'parse_args' would produce a 'error: unrecognized arguments: -_' error.

I don't see how the error message could be improved without some major changes in the testing and parsing.  It would either have to disallow unmatched optional's flags (and maybe break subparsers) or deduce that this 'extra' was meant for the unfilled positional.  Bernard has argued that it is better to raise an error in ambiguous cases, than to make too many assumptions about what the user intended.
History
Date User Action Args
2017-03-12 17:45:04paul.j3setrecipients: + paul.j3, r.david.murray, martin.panter, Max Rothman
2017-03-12 17:45:04paul.j3setmessageid: <1489340704.53.0.19495012093.issue29715@psf.upfronthosting.co.za>
2017-03-12 17:45:04paul.j3linkissue29715 messages
2017-03-12 17:45:04paul.j3create