Skip to content
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

Closed
jensjaehrig mannequin opened this issue May 25, 2012 · 24 comments
Closed

argparse: disable abbreviation #59115

jensjaehrig mannequin opened this issue May 25, 2012 · 24 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@jensjaehrig
Copy link
Mannequin

jensjaehrig mannequin commented May 25, 2012

BPO 14910
Nosy @ericvsmith, @bitdancer, @berkerpeksag, @remram44
Files
  • disable-abbrev.patch: Patch wi/tests,doc
  • 14910.patch
  • issue14910_2.patch
  • issue_14910_3.diff
  • issue14910_4.diff
  • issue14910_5.diff
  • issue14910_6.diff
  • issue14910_7.diff.txt
  • 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:

    assignee = 'https://github.com/berkerpeksag'
    closed_at = <Date 2015-02-13.23:41:44.333>
    created_at = <Date 2012-05-25.10:59:55.919>
    labels = ['type-feature', 'library']
    title = 'argparse: disable abbreviation'
    updated_at = <Date 2015-02-13.23:41:44.332>
    user = 'https://bugs.python.org/jensjaehrig'

    bugs.python.org fields:

    activity = <Date 2015-02-13.23:41:44.332>
    actor = 'berker.peksag'
    assignee = 'berker.peksag'
    closed = True
    closed_date = <Date 2015-02-13.23:41:44.333>
    closer = 'berker.peksag'
    components = ['Library (Lib)']
    creation = <Date 2012-05-25.10:59:55.919>
    creator = 'jens.jaehrig'
    dependencies = []
    files = ['25729', '26481', '35191', '36207', '36228', '36229', '36246', '36260']
    hgrepos = []
    issue_num = 14910
    keywords = ['patch']
    message_count = 24.0
    messages = ['161566', '161672', '161680', '166160', '166161', '166162', '187235', '204678', '218137', '224557', '224567', '224616', '224617', '224629', '224654', '224699', '224775', '225009', '234476', '234477', '235362', '235421', '235926', '235928']
    nosy_count = 15.0
    nosy_names = ['bethard', 'eric.smith', 'r.david.murray', 'eli.bendersky', 'daniel.ugra', 'tshepang', 'python-dev', 'berker.peksag', 'paul.j3', 'jens.jaehrig', 'jpaugh', 'puppet', 'Michael.Edwards', 'remram', 'xobes']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue14910'
    versions = ['Python 3.5']

    @jensjaehrig jensjaehrig mannequin added the type-feature A feature request or enhancement label May 25, 2012
    @jensjaehrig
    Copy link
    Mannequin Author

    jensjaehrig mannequin commented May 25, 2012

    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.

    @jensjaehrig jensjaehrig mannequin changed the title argparse disable abbreviation argparse: disable abbreviation May 25, 2012
    @jpaugh
    Copy link
    Mannequin

    jpaugh mannequin commented May 26, 2012

    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.

    @jpaugh
    Copy link
    Mannequin

    jpaugh mannequin commented May 26, 2012

    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.

    @bethard
    Copy link
    Mannequin

    bethard mannequin commented Jul 22, 2012

    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

    @bethard
    Copy link
    Mannequin

    bethard mannequin commented Jul 22, 2012

    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!

    @bitdancer
    Copy link
    Member

    bitdancer commented Jul 22, 2012

    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.

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Apr 18, 2013

    Ping :)

    @paulj3
    Copy link
    Mannequin

    paulj3 mannequin commented Nov 28, 2013

    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').

    @paulj3
    Copy link
    Mannequin

    paulj3 mannequin commented May 9, 2014

    Update the patch -
    test_argparse.py - cleanup spaces
    argparse.rst - merging conflicts

    @puppet
    Copy link
    Mannequin

    puppet mannequin commented Aug 2, 2014

    Update the patch - issue_14910_3.diff
    argparse.rst - merging conflicts

    @elibendersky
    Copy link
    Mannequin

    elibendersky mannequin commented Aug 2, 2014

    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.

    @puppet
    Copy link
    Mannequin

    puppet mannequin commented Aug 3, 2014

    Oh, completely missed comments there too!

    I hope I got them all in a good way!

    @puppet
    Copy link
    Mannequin

    puppet mannequin commented Aug 3, 2014

    Sorry for a new patch this close, but just tripple checked the documentation and noticed a word to much. Made it more clear hopefully

    @elibendersky
    Copy link
    Mannequin

    elibendersky mannequin commented Aug 3, 2014

    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.

    @puppet
    Copy link
    Mannequin

    puppet mannequin commented Aug 3, 2014

    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.

    @berkerpeksag berkerpeksag added the stdlib Python modules in the Lib dir label Aug 4, 2014
    @puppet
    Copy link
    Mannequin

    puppet mannequin commented Aug 4, 2014

    Fixed documentation issues

    @puppet
    Copy link
    Mannequin

    puppet mannequin commented Aug 4, 2014

    Updated patch

    @elibendersky
    Copy link
    Mannequin

    elibendersky mannequin commented Aug 7, 2014

    Ezio, could you see if your comments were addressed?

    Steven, do you want to take another look, or is this OK to commit?

    @xobes
    Copy link
    Mannequin

    xobes mannequin commented Jan 22, 2015

    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'

    @xobes
    Copy link
    Mannequin

    xobes mannequin commented Jan 22, 2015

    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.

    @remram44
    Copy link
    Mannequin

    remram44 mannequin commented Feb 3, 2015

    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.

    @berkerpeksag
    Copy link
    Member

    berkerpeksag commented Feb 5, 2015

    The patch LGTM.

    In Doc/library/argparse.rst:

    •                      add_help=True)
      

    + allow_abbrev=True, add_help=True)

    should be

        add_help=True, allow_abbrev=True)

    I'll add a release note and commit it. Thanks!

    @berkerpeksag berkerpeksag self-assigned this Feb 5, 2015
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 13, 2015

    New changeset 99302634d756 by Berker Peksag in branch 'default':
    Issue bpo-14910: Add allow_abbrev parameter to argparse.ArgumentParser.
    https://hg.python.org/cpython/rev/99302634d756

    @berkerpeksag
    Copy link
    Member

    berkerpeksag commented Feb 13, 2015

    Committed. Thank you all for patches and reviews :)

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants