[issue32756] argparse: parse_known_args: raising exception on unknown arg following known one

Yauhen report at bugs.python.org
Wed Feb 14 06:22:55 EST 2018


Yauhen <actionless.loveless at gmail.com> added the comment:

I am adding one more testcase in order to clarify more the problem:



import argparse
import sys

parser = argparse.ArgumentParser(prog=sys.argv[0], add_help=False)
parser.add_argument('-a', action='store_true')
parser.add_argument('-b', action='store_true')
parser.add_argument('-c', action='store_true')
parsed_args, unknown_args = parser.parse_known_args(sys.argv[1:])
print(parsed_args)
print(unknown_args)



$ python argparse_test.py -ab
Namespace(a=True, b=True, c=False)
[]


Expected result:
$ python argparse_test.py -ab -cd
Namespace(a=True, b=True, c=True)
['-d']

Actual result:
$ python argparse_test.py -ab -cd
usage: argparse_test.py [-a] [-b] [-c]
argparse_test.py: error: argument -c: ignored explicit argument 'd'

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32756>
_______________________________________


More information about the Python-bugs-list mailing list