
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2016-05-05 19:04 bymeinersbur, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 14316 | merged | Zac Hatfield-Dodds,2019-06-23 03:34 | |
| PR 14759 | merged | miss-islington,2019-07-14 05:36 | |
| PR 18337 | merged | kyleam,2020-02-03 20:18 | |
| PR 18543 | merged | miss-islington,2020-02-18 09:49 | |
| Messages (13) | |||
|---|---|---|---|
| msg264915 -(view) | Author: Michael Kruse (meinersbur) | Date: 2016-05-05 19:04 | |
#! /usr/bin/env python3import argparseparser = argparse.ArgumentParser(allow_abbrev=True)parser.add_argument('-v', '--verbose', action='count')print(parser.parse_args(['-vv']))parser = argparse.ArgumentParser(allow_abbrev=False)parser.add_argument('-v', '--verbose', action='count')print(parser.parse_args(['-vv']))Observed Output:Namespace(verbose=2)usage: test.py [-h] [-v]test.py: error: unrecognized arguments: -vvExpected Output:Namespace(verbose=2)Namespace(verbose=2) | |||
| msg264930 -(view) | Author: Xiang Zhang (xiang.zhang)*![]() | Date: 2016-05-06 03:19 | |
This is a side effect introduced by99302634d756. You have to set allow_abbrev to True to make such match succeed. I think this is a bug. | |||
| msg264931 -(view) | Author: Xiang Zhang (xiang.zhang)*![]() | Date: 2016-05-06 04:14 | |
After some research I suggest to document this behaviour that allow_abbrev=False will suspend option prefix matching. Simply fixing the count action behaviour is not enough since it also prevents you from creating custom actions that want to use option prefix matching. What's your advice berker? | |||
| msg264975 -(view) | Author: Michael Kruse (meinersbur) | Date: 2016-05-06 14:53 | |
I think the allow_abbrev option should be orthogonal on how short options are parsed. I am using parse_known_args() to forward the unrecognized args to another program, therefore allow_abbrev=False is essential.There is a special handling for short options in the consume_optional and _get_option_tuples to allow them being concatenated with one dash, as commonly done with short options (eg. "tar -czf file"). I interpret allow_abbrev as an option to avoid matching non-exiting options that should be forwarded to the other program; '-vv' is an existing option with the same meaning as '-v -v'.This would also mean that parse_known_args(['-vz']) (where '-v' is a registered argument, but '-z' is not) matches '-v' and returns '-z' as unknown argument; but I don't know whether you want to go that far. It is difficult to interpret whether '-verify' should mean '-v -e -r -i -f -y' or '--verify' (but this is why there are double-dash options), especially when the first letter is not a registered short option. | |||
| msg265004 -(view) | Author: Xiang Zhang (xiang.zhang)*![]() | Date: 2016-05-06 17:51 | |
I agree with you. But right now, it seems parsing short options and allow_abbrev both rely on the same logic. If you turn off allow_abbrev, short options parsing also disabled. Separating them seems nontrivial. | |||
| msg265161 -(view) | Author: paul j3 (paul.j3)*![]() | Date: 2016-05-08 19:47 | |
It's been 2 years since I worked on this patch. In the issue discussionhttp://bugs.python.org/issue14910 there was no mention of short v long options. The unit tests only look at longs.The result is that with the abbrev off, it disables all use of combined shorts, not just the count. Not only if '-vv' disabled, so is '-vz', '-vz1', '-v -z1'.We should have discussed that issue.I can imagine modifying the if self.allow_abbrev:to something like if self.allow_abbrev or <argstring has only one dash>: <search for abbreviations>But even if we don't go that far, we should add a documentation note. | |||
| msg265167 -(view) | Author: paul j3 (paul.j3)*![]() | Date: 2016-05-08 20:55 | |
Someone needs to take the current argparse.py, set the default value of this parameter to False, and run the unittest file. This should turn up this case, and possibly others that fail when abbreviations are turned off. Then we have to debate whether such failures are acceptable or not.When we say 'disable abbreviations' do we mean, all abbreviations, or just a subset? | |||
| msg337379 -(view) | Author: Lukáš Hrázký (lukash) | Date: 2019-03-07 09:45 | |
Sad to see this still wasn't fixed. The abbreviation "feature" creates ambiguity and room for error and this bug makes the switch unusable for a lot of applications. | |||
| msg347169 -(view) | Author: daniel hahler (blueyed)* | Date: 2019-07-02 23:04 | |
https://github.com/python/cpython/pull/14316 has a fix. | |||
| msg347864 -(view) | Author: miss-islington (miss-islington) | Date: 2019-07-14 05:36 | |
New changesetdffca9e925ee5c3072663cbe8d4d4768406d5307 by Miss Islington (bot) (Zac Hatfield-Dodds) in branch 'master':bpo-26967: fix flag grouping with allow_abbrev=False (GH-14316)https://github.com/python/cpython/commit/dffca9e925ee5c3072663cbe8d4d4768406d5307 | |||
| msg347865 -(view) | Author: Petr Viktorin (petr.viktorin)*![]() | Date: 2019-07-14 06:00 | |
New changesetb1e4d1b6032d4c82b549233fa08a2c7cfe7e818b by Petr Viktorin (Miss Islington (bot)) in branch '3.8':bpo-26967: fix flag grouping with allow_abbrev=False (GH-14316) (GH-14759)https://github.com/python/cpython/commit/b1e4d1b6032d4c82b549233fa08a2c7cfe7e818b | |||
| msg362184 -(view) | Author: miss-islington (miss-islington) | Date: 2020-02-18 09:49 | |
New changeset8edfc47baec7ff4cb1b9db83dd35c8ffc1d498a4 by Kyle Meyer in branch 'master':bpo-39546: argparse: Honor allow_abbrev=False for specified prefix_chars (GH-18337)https://github.com/python/cpython/commit/8edfc47baec7ff4cb1b9db83dd35c8ffc1d498a4 | |||
| msg362194 -(view) | Author: miss-islington (miss-islington) | Date: 2020-02-18 11:14 | |
New changesete412cbba52e7cf6699720d99a4b88baef92db7b2 by Miss Islington (bot) in branch '3.8':[3.8]bpo-39546: argparse: Honor allow_abbrev=False for specified prefix_chars (GH-18337) (GH-18543)https://github.com/python/cpython/commit/e412cbba52e7cf6699720d99a4b88baef92db7b2 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:30 | admin | set | github: 71154 |
| 2020-02-18 11:14:11 | miss-islington | set | messages: +msg362194 |
| 2020-02-18 09:49:13 | miss-islington | set | pull_requests: +pull_request17921 |
| 2020-02-18 09:49:07 | miss-islington | set | messages: +msg362184 |
| 2020-02-03 20:18:15 | kyleam | set | pull_requests: +pull_request17710 |
| 2019-07-14 07:40:56 | petr.viktorin | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2019-07-14 06:00:04 | petr.viktorin | set | nosy: +petr.viktorin messages: +msg347865 |
| 2019-07-14 05:36:12 | miss-islington | set | pull_requests: +pull_request14553 |
| 2019-07-14 05:36:03 | miss-islington | set | nosy: +miss-islington messages: +msg347864 |
| 2019-07-02 23:04:39 | blueyed | set | nosy: +blueyed messages: +msg347169 versions: + Python 3.7, Python 3.8, Python 3.9 |
| 2019-06-23 03:34:25 | Zac Hatfield-Dodds | set | keywords: +patch stage: needs patch -> patch review pull_requests: +pull_request14140 |
| 2019-03-07 09:45:36 | lukash | set | nosy: +lukash messages: +msg337379 |
| 2017-11-16 08:01:13 | berker.peksag | link | issue32027 superseder |
| 2016-05-08 20:55:03 | paul.j3 | set | messages: +msg265167 |
| 2016-05-08 19:47:53 | paul.j3 | set | priority: normal -> high |
| 2016-05-08 19:47:36 | paul.j3 | set | nosy: +paul.j3 messages: +msg265161 |
| 2016-05-06 17:51:41 | xiang.zhang | set | messages: +msg265004 |
| 2016-05-06 14:53:26 | meinersbur | set | messages: +msg264975 |
| 2016-05-06 04:14:59 | xiang.zhang | set | nosy: +bethard messages: +msg264931 |
| 2016-05-06 03:19:37 | xiang.zhang | set | messages: +msg264930 |
| 2016-05-06 02:55:10 | xiang.zhang | set | nosy: +xiang.zhang |
| 2016-05-05 19:16:04 | berker.peksag | set | keywords: +3.5regression nosy: +berker.peksag stage: needs patch versions: + Python 3.6 |
| 2016-05-05 19:04:46 | meinersbur | create | |