classification
Title: argparse: disable abbreviation
Type: enhancement Stage:
Components: None Versions: Python 3.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, Michael.Edwards, bethard, daniel.ugra, jens.jaehrig, jpaugh, r.david.murray, tshepang
Priority: normal Keywords: patch

Created on 2012-05-25 10:59 by jens.jaehrig, last changed 2013-04-18 10:24 by BreamoreBoy.

Files
File name Uploaded Description Edit
disable-abbrev.patch jpaugh, 2012-05-26 20:26 Patch wi/tests,doc review
14910.patch bethard, 2012-07-22 19:57 review
Messages (7)
msg161566 - (view) Author: Jens Jährig (jens.jaehrig) Date: 2012-05-25 11:02
argparse uses per default abbreviation in unambiguous cases.

I don't want abbreviation and i'd like to disable it.
But theres no option to do this.
http://docs.python.org/library/argparse.html#argument-abbreviations
Only to override the Handler like suggested here: http://stackoverflow.com/questions/10750802/python-argparse-disable-abbreviation/10751356#10751356

################
# Example      #
################

    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('--send', action='store_true')
    parser.parse_args(['--se']) # returns Namespace(send=True)

But i want it only to be true when the full parameter is supplied. To prevent user errors.
msg161672 - (view) Author: Jonathan Paugh (jpaugh) Date: 2012-05-26 17:54
I am dubious as to the use of this: I think resolving partial args is one of the best thing since invented since sliced bread.

However, it's a good project to get my feet wet, so I'll take it on. I should have a patch later today--I'm working on test-cases just now.
msg161680 - (view) Author: Jonathan Paugh (jpaugh) Date: 2012-05-26 20:26
I created a patch that exibhts the requested behavior. I added tests, and updated the documentation. I ran the test-suite against a build of Python 3.3.0a3+, and all tests check out.

This changes the public API of argparse.ArgumentParser and of its parse_args() method.
msg166160 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2012-07-22 19:57
I think it makes a lot of sense to allow people to disable abbreviations, so +1 on the feature request.

The patch looked good. There was one typo - using "accept_abbrev" in the docstring instead of "allow_abbrev" as in the implementation, and I fixed that and uploaded a new patch.

To be complete, the patch also needs to add some documentation, edit Misc/NEWS, etc. See:

http://docs.python.org/devguide/patch.html#preparation
msg166161 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2012-07-22 19:58
Sorry, my mistake, the doc changes were already in the patch. I just checked them and they look good too. So everything's ready to commit.

Thanks for your contribution!
msg166162 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-07-22 20:06
Jonathan: we are in feature freeze right now preparing 3.3 for release, so you might want to ping the issue once 3.3 is out to remind us to do the checkin.
msg187235 - (view) Author: Mark Lawrence (BreamoreBoy) Date: 2013-04-18 10:24
Ping :)
History
Date User Action Args
2013-04-18 10:24:22BreamoreBoysetnosy: + BreamoreBoy
messages: + msg187235
2013-02-05 15:11:49daniel.ugrasetnosy: + daniel.ugra
2012-12-05 18:45:51r.david.murraylinkissue16614 superseder
2012-12-05 18:45:11r.david.murraysetnosy: + Michael.Edwards
2012-07-22 20:06:32r.david.murraysetnosy: + r.david.murray
messages: + msg166162
2012-07-22 19:58:17bethardsetmessages: + msg166161
2012-07-22 19:57:10bethardsetfiles: + 14910.patch

messages: + msg166160
versions: + Python 3.4, - Python 3.3
2012-05-26 20:26:38jpaughsetfiles: + disable-abbrev.patch
keywords: + patch
messages: + msg161680
2012-05-26 17:54:05jpaughsetnosy: + jpaugh
messages: + msg161672
2012-05-25 18:42:27eric.araujosetversions: + Python 3.3, - Python 2.6, Python 2.7
2012-05-25 16:26:59tshepangsetnosy: + bethard, tshepang
2012-05-25 11:04:16jens.jaehrigsettitle: argparse disable abbreviation -> argparse: disable abbreviation
2012-05-25 11:02:22jens.jaehrigsetmessages: + msg161566
2012-05-25 10:59:55jens.jaehrigcreate