-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
argparse: disable abbreviation #59115
Comments
argparse uses per default abbreviation in unambiguous cases. I don't want abbreviation and i'd like to disable it. ################ 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. |
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. |
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. |
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: |
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! |
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. |
Ping :) |
For a programmer who needs to turn off this abbreviation matching now, a simple solution is to subclass ArgumentParser: class MyParser(ArgumentParser):
def _get_option_tuples(self, option_string):
return [] This could be the place to implement more specialized matching (e.g. do not match on strings like '--sync'). |
Update the patch - |
Update the patch - issue_14910_3.diff |
Daniel, I left some comments in Rietveld. Also it doesn't seem that you addressed the previously left comments when you fixed up the patch. |
Oh, completely missed comments there too! I hope I got them all in a good way! |
Sorry for a new patch this close, but just tripple checked the documentation and noticed a word to much. Made it more clear hopefully |
No worries, Daniel. You should have received an email when comments were posted to the review, did you? If you you may want to check your settings in the bug tracker. I left a couple of additional comments on the documentation file, but other than that this LGTM. |
Eli, will look into those tomorrow morning, so a final patch will come during tomorrow. Checked my spam folder - and there they where, fixed the settings now so I get it faster. |
Fixed documentation issues |
Updated patch |
Ezio, could you see if your comments were addressed? Steven, do you want to take another look, or is this OK to commit? |
This breaks custom actions. e.g.: class dict_action(argparse.Action):
def __init__(self, *a, **k):
argparse.Action.__init__(self, *a, **k) TypeError: __init__() got an unexpected keyword argument 'allow_abbrev' |
Ignore previous comment, I wish I could delete it. I simply provided the allow_abbrev to the wrong function and spent zero time investigating the error. |
It looks like the previous comments were addressed in the latest patch. Is this still planned for 3.5? Alpha 1 is next week according to PEP-478. |
The patch LGTM.
+ allow_abbrev=True, add_help=True) should be add_help=True, allow_abbrev=True) I'll add a release note and commit it. Thanks! |
New changeset 99302634d756 by Berker Peksag in branch 'default': |
Committed. Thank you all for patches and reviews :) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: