import argparse
p = argparse.ArgumentParser()
p.add_argument('arg1', type=str)
p.add_argument('args', nargs='*')
p.parse_args(['foo', '--', '--bar', '--', 'com'])
Namespace(arg1='foo', args=['--bar', '--', 'com'])
Namespace(arg1='foo', args=['--bar', 'com'])
p = argparse.ArgumentParser()
p.add_argument('args', nargs='*')
p.parse_args(['foo', '--', '--bar', '--', 'com'])
--> Namespace(args=['foo', '--bar', '--', 'com'])
Consider this:
The semantics of
--are to not attempt to parse the remaining command line options as parameters. Therefore, the expected output is:However, the actual output is:
In other words, the second
--has silently been dropped.Interestingly enough, if the
arg1parameter is dropped, this works correctly:Linked PRs
--in cases where used to delineate positional args #124145