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 bethard, chriz, eric.araujo, ned.deily, paul.j3, pwil3058, python-dev, tshepang, vinay.sajip, zach.ware
Date 2016-08-20.00:14:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1471652065.46.0.745493133979.issue12713@psf.upfronthosting.co.za>
In-reply-to
Content
I haven't read the discussion in full, but it looks like this patch was added without any recent discussion or testing.

Previously if we had `choices=['a','abc']`, any exact match would be accepted, and partial matches rejected.  With this change the only choice that will work is the longest, 'abc'.  The other will be rejected as ambiguous.

In contrast with optionals flags, an exact match has priority over (possibly ambiguous) abbreviations.  See parser._parse_optional

I also noticed when testing this that for regular 'choices', the abbreviated string is put in the Namespace.  

     add_argument('--foo', choices = ['one','two'])

can produce `Namespace(foo='on')`.  I suspect most developers would want `Namespace(foo='one')`, regardless of whether it was an exact match or partial.  You don't list choices if you are ok with partial matches.

This isn't a problem with `subparsers`, since an abbreviation match still invokes the right subparser, and even puts the right name in 'subparsers' dest.  But for regular choices the behavior is highly debatable.

This needs to be reverted.  It may be fixable, but it needs more testing and discussion.  For now it's an enhancement that is causing backward compatibility problems.

ps

I missed this issue when I made an effort to find all argparse issues several years ago.  I contributed to https://bugs.python.org/issue14365, the other abbreviations issue mentioned in the recent github thread.
History
Date User Action Args
2016-08-20 00:14:25paul.j3setrecipients: + paul.j3, vinay.sajip, bethard, ned.deily, eric.araujo, pwil3058, tshepang, python-dev, chriz, zach.ware
2016-08-20 00:14:25paul.j3setmessageid: <1471652065.46.0.745493133979.issue12713@psf.upfronthosting.co.za>
2016-08-20 00:14:25paul.j3linkissue12713 messages
2016-08-20 00:14:23paul.j3create