[Python-checkins] cpython (2.7): #12353: argparse now correctly handles null argument values.

r.david.murray python-checkins at python.org
Sun Jul 22 04:35:33 CEST 2012


http://hg.python.org/cpython/rev/c9806f0aaefb
changeset:   78231:c9806f0aaefb
branch:      2.7
parent:      78228:905d9bdae970
user:        R David Murray <rdmurray at bitdance.com>
date:        Sat Jul 21 22:35:00 2012 -0400
summary:
  #12353: argparse now correctly handles null argument values.

Patch by Torsten Landschoff.

files:
  Lib/argparse.py           |  2 +-
  Lib/test/test_argparse.py |  1 +
  Misc/NEWS                 |  2 ++
  3 files changed, 4 insertions(+), 1 deletions(-)


diff --git a/Lib/argparse.py b/Lib/argparse.py
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -1967,7 +1967,7 @@
         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
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -1374,6 +1374,7 @@
         ('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'])),
     ]
 
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -90,6 +90,8 @@
 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.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list