]> granicus.if.org Git - python/commitdiff
#12353: argparse now correctly handles null argument values.
authorR David Murray <rdmurray@bitdance.com>
Sun, 22 Jul 2012 02:35:00 +0000 (22:35 -0400)
committerR David Murray <rdmurray@bitdance.com>
Sun, 22 Jul 2012 02:35:00 +0000 (22:35 -0400)
Patch by Torsten Landschoff.

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

index d8676118388624b42d78c2dd2f65928c0649f5ea..f365385a5739efe64aa4865e310acffe52700ce4 100644 (file)
@@ -1967,7 +1967,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 1a5f05e30b9fab993609463fb693b4ab0ad59bc1..a7a4b005b0075ad2b7be183a54287d6addad51ac 100644 (file)
@@ -1374,6 +1374,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 16ab20224c6c7ab65372b8895a86851e8e177ab5..7a2eb5bb528c7b1fe46a0543943ad7e2f9333c75 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -90,6 +90,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #12353: argparse now correctly handles null argument values.
+
 - Issue #6493: An issue in ctypes on Windows that caused structure bitfields
   of type ctypes.c_uint32 and width 32 to incorrectly be set has been fixed.