@@ -6036,6 +6036,20 @@ def test_remainder(self):
60366036 args = parser .parse_args (['--foo' , 'a' , '--' , 'b' , '--' , 'c' ])
60376037 self .assertEqual (NS (foo = 'a' , bar = ['--' , 'b' , '--' , 'c' ]), args )
60386038
6039+ def test_optional_remainder (self ):
6040+ parser = argparse .ArgumentParser (exit_on_error = False )
6041+ parser .add_argument ('--foo' , nargs = '...' )
6042+ parser .add_argument ('bar' , nargs = '*' )
6043+
6044+ args = parser .parse_args (['--' , '--foo' , 'a' , 'b' ])
6045+ self .assertEqual (NS (foo = None , bar = ['--foo' , 'a' , 'b' ]), args )
6046+ args = parser .parse_args (['--foo' , '--' , 'a' , 'b' ])
6047+ self .assertEqual (NS (foo = ['--' , 'a' , 'b' ], bar = []), args )
6048+ args = parser .parse_args (['--foo' , 'a' , '--' , 'b' ])
6049+ self .assertEqual (NS (foo = ['a' , '--' , 'b' ], bar = []), args )
6050+ args = parser .parse_args (['--foo' , 'a' , 'b' , '--' ])
6051+ self .assertEqual (NS (foo = ['a' , 'b' , '--' ], bar = []), args )
6052+
60396053 def test_subparser (self ):
60406054 parser = argparse .ArgumentParser (exit_on_error = False )
60416055 parser .add_argument ('foo' )
0 commit comments