@@ -6605,6 +6605,20 @@ def test_remainder(self):
66056605 args = parser .parse_args (['--foo' , 'a' , '--' , 'b' , '--' , 'c' ])
66066606 self .assertEqual (NS (foo = 'a' , bar = ['--' , 'b' , '--' , 'c' ]), args )
66076607
6608+ def test_optional_remainder (self ):
6609+ parser = argparse .ArgumentParser (exit_on_error = False )
6610+ parser .add_argument ('--foo' , nargs = '...' )
6611+ parser .add_argument ('bar' , nargs = '*' )
6612+
6613+ args = parser .parse_args (['--' , '--foo' , 'a' , 'b' ])
6614+ self .assertEqual (NS (foo = None , bar = ['--foo' , 'a' , 'b' ]), args )
6615+ args = parser .parse_args (['--foo' , '--' , 'a' , 'b' ])
6616+ self .assertEqual (NS (foo = ['--' , 'a' , 'b' ], bar = []), args )
6617+ args = parser .parse_args (['--foo' , 'a' , '--' , 'b' ])
6618+ self .assertEqual (NS (foo = ['a' , '--' , 'b' ], bar = []), args )
6619+ args = parser .parse_args (['--foo' , 'a' , 'b' , '--' ])
6620+ self .assertEqual (NS (foo = ['a' , 'b' , '--' ], bar = []), args )
6621+
66086622 def test_subparser (self ):
66096623 parser = argparse .ArgumentParser (exit_on_error = False )
66106624 parser .add_argument ('foo' )
0 commit comments