#12353: argparse now correctly handles null argument values.
authorR David Murray <rdmurray@bitdance.com>
Sun, 22 Jul 2012 02:20:11 +0000 (22:20 -0400)
committerR David Murray <rdmurray@bitdance.com>
Sun, 22 Jul 2012 02:20:11 +0000 (22:20 -0400)
Patch by Torsten Landschoff.

Lib/argparse.py
Lib/test/test_argparse.py
Misc/NEWS

index cf0097bf48e261fb50a7952c579af2ffaac92fe9..25803b35195e7762b6104fbc06d0b51b8c4de211 100644 (file)
@@ -1976,7 +1976,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
         for arg_string in arg_strings:
 
             # for regular arguments, just add them back into the list
-            if arg_string[0] not in self.fromfile_prefix_chars:
+            if not arg_string or arg_string[0] not in self.fromfile_prefix_chars:
                 new_arg_strings.append(arg_string)
 
             # replace arguments referencing files with the file content
index 852991c77f2466894b172416095ac15473cc884a..1a72a13e30deee30ab34038369f7e884ed2b70a9 100644 (file)
@@ -1371,6 +1371,7 @@ class TestArgumentsFromFile(TempDirMixin, ParserTestCase):
         ('X @hello', NS(a=None, x='X', y=['hello world!'])),
         ('-a B @recursive Y Z', NS(a='A', x='hello world!', y=['Y', 'Z'])),
         ('X @recursive Z -a B', NS(a='B', x='X', y=['hello world!', 'Z'])),
+        (["-a", "", "X", "Y"], NS(a='', x='X', y=['Y'])),
     ]
 
 
index 3d4d049852b3818c4b660f94d5eb8b8a6008c27e..57f3650f482b001d59b2b54a294de959be8cd71a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -98,6 +98,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #12353: argparse now correctly handles null argument values.
+
 - Issues #10017 and #14998: Fix TypeError using pprint on dictionaries with
   user-defined types as keys or other unorderable keys.