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 martin.panter
Recipients Max Rothman, martin.panter, r.david.murray
Date 2017-03-04.00:32:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1488587566.96.0.430918757087.issue29715@psf.upfronthosting.co.za>
In-reply-to
Content
This is actually expected behaviour of the “argparse”, as well as general Unix CLI programs. See the documentation <https://docs.python.org/3.6/library/argparse.html#arguments-containing>. The general workaround is to use a double-dash separator:

>>> parser.parse_args(['--', '-_'])
Namespace(first='-_')

Example with the Gnu “rm” command:

$ echo "make a file" >-_
$ rm -_
rm: invalid option -- '_'
Try 'rm ./-_' to remove the file '-_'.
Try 'rm --help' for more information.
[Exit 1]
$ rm -- -_  # Double dash also works

Although I suppose the error message could be improved. Currently it looks like it ignores the argument:

>>> parser.parse_args(['-_'])
usage: [-h] first
: error: the following arguments are required: first
__main__.SystemExit: 2
History
Date User Action Args
2017-03-04 00:32:46martin.pantersetrecipients: + martin.panter, r.david.murray, Max Rothman
2017-03-04 00:32:46martin.pantersetmessageid: <1488587566.96.0.430918757087.issue29715@psf.upfronthosting.co.za>
2017-03-04 00:32:46martin.panterlinkissue29715 messages
2017-03-04 00:32:46martin.pantercreate