paul j3 <ajipa...@gmail.com> added the comment:
In your first example: In [29]: parser = argparse39.ArgumentParser(allow_abbrev=True) In [30]: parser.add_argument('-o'); In [32]: parser.parse_known_args(['-o','test']) Out[32]: (Namespace(o='test'), []) In [33]: parser.parse_known_args(['-object','test']) Out[33]: (Namespace(o='bject'), ['test']) Here the '-object' is interpreted as '-o' flag, with value the rest of the string. That's normal behavior for a short option. In [34]: parser.parse_known_args(['-o','test1','-object','test2']) Out[34]: (Namespace(o='bject'), ['test2']) Same thing only '-object' has overwritten the 'test1' value. In your second example: In [39]: parser = argparse39.ArgumentParser(allow_abbrev=False) In [40]: parser.add_argument('-verbose'); In [42]: parser.parse_known_args(['-v', '-verbose=2']) usage: ipython3 [-h] [-verbose VERBOSE] ipython3: error: argument -verbose: expected one argument Expected uses: In [46]: parser.parse_known_args(['-verbose','two']) Out[46]: (Namespace(verbose='two'), []) In [47]: parser.parse_known_args(['-verbose=2']) Out[47]: (Namespace(verbose='2'), []) The '-ver' is not accepted as abbreviation: In [48]: parser.parse_known_args(['-ver=2']) Out[48]: (Namespace(verbose=None), ['-ver=2']) 'allow_abbrev' doesn't have effect because of '-verbose' If instead I define '--verbose', I can turn the abbrev on/off: In [49]: parser = argparse39.ArgumentParser(allow_abbrev=False) In [50]: parser.add_argument('--verbose'); In [51]: parser.parse_known_args(['-ver=2']) Out[51]: (Namespace(verbose=None), ['-ver=2']) In [52]: parser.parse_known_args(['--ver=2']) Out[52]: (Namespace(verbose=None), ['--ver=2']) In [53]: parser.allow_abbrev=True In [54]: parser.parse_known_args(['--ver=2']) Out[54]: (Namespace(verbose='2'), []) There are a lot of variations to examine here. The original, the 3.7, and 3.8 versions. abbrev False or True. Proper long option (--), improper etc. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue41534> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com