[issue26967] argparse: allow_abbrev=False stops -vv from working
New submission from Michael Kruse: #! /usr/bin/env python3 import argparse parser = 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: -vv Expected Output: Namespace(verbose=2) Namespace(verbose=2) -- components: Library (Lib) messages: 264915 nosy: meinersbur priority: normal severity: normal status: open title: argparse: allow_abbrev=False stops -vv from working type: behavior versions: Python 3.5 ___ Python tracker <http://bugs.python.org/issue26967> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue26967] argparse: allow_abbrev=False stops -vv from working
Michael Kruse added the comment: 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. -- ___ Python tracker <http://bugs.python.org/issue26967> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com