mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-53780: Ignore the first "--" (double dash) between an option and command in argparse (GH-124275)
This commit is contained in:
parent
3094cd17b0
commit
c578271366
3 changed files with 23 additions and 4 deletions
|
@ -5984,6 +5984,20 @@ class TestDoubleDash(TestCase):
|
|||
"invalid choice: '--'",
|
||||
parser.parse_args, ['--', 'x', '--', 'run', 'a', 'b'])
|
||||
|
||||
def test_subparser_after_multiple_argument_option(self):
|
||||
parser = argparse.ArgumentParser(exit_on_error=False)
|
||||
parser.add_argument('--foo', nargs='*')
|
||||
subparsers = parser.add_subparsers()
|
||||
parser1 = subparsers.add_parser('run')
|
||||
parser1.add_argument('-f')
|
||||
parser1.add_argument('bar', nargs='*')
|
||||
|
||||
args = parser.parse_args(['--foo', 'x', 'y', '--', 'run', 'a', 'b', '-f', 'c'])
|
||||
self.assertEqual(NS(foo=['x', 'y'], f='c', bar=['a', 'b']), args)
|
||||
self.assertRaisesRegex(argparse.ArgumentError,
|
||||
"invalid choice: '--'",
|
||||
parser.parse_args, ['--foo', 'x', '--', '--', 'run', 'a', 'b'])
|
||||
|
||||
|
||||
# ===========================
|
||||
# parse_intermixed_args tests
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue