[Python-checkins] r67572 - in python/trunk: Lib/getopt.py Lib/test/test_getopt.py Misc/NEWS

georg.brandl python-checkins at python.org
Fri Dec 5 10:23:14 CET 2008


Author: georg.brandl
Date: Fri Dec  5 10:23:14 2008
New Revision: 67572

Log:
#4458: recognize "-" as an argument, not a malformed option in gnu_getopt().


Modified:
   python/trunk/Lib/getopt.py
   python/trunk/Lib/test/test_getopt.py
   python/trunk/Misc/NEWS

Modified: python/trunk/Lib/getopt.py
==============================================================================
--- python/trunk/Lib/getopt.py	(original)
+++ python/trunk/Lib/getopt.py	Fri Dec  5 10:23:14 2008
@@ -130,7 +130,7 @@
 
         if args[0][:2] == '--':
             opts, args = do_longs(opts, args[0][2:], longopts, args[1:])
-        elif args[0][:1] == '-':
+        elif args[0][:1] == '-' and args[0] != '-':
             opts, args = do_shorts(opts, args[0][1:], shortopts, args[1:])
         else:
             if all_options_first:

Modified: python/trunk/Lib/test/test_getopt.py
==============================================================================
--- python/trunk/Lib/test/test_getopt.py	(original)
+++ python/trunk/Lib/test/test_getopt.py	Fri Dec  5 10:23:14 2008
@@ -124,6 +124,11 @@
         self.assertEqual(opts, [('-a', ''), ('-b', '1'),
                                 ('--alpha', ''), ('--beta', '2')])
 
+        # recognize "-" as an argument
+        opts, args = getopt.gnu_getopt(['-a', '-', '-b', '-'], 'ab:', [])
+        self.assertEqual(args, ['-'])
+        self.assertEqual(opts, [('-a', ''), ('-b', '-')])
+
         # Posix style via +
         opts, args = getopt.gnu_getopt(cmdline, '+ab:', ['alpha', 'beta='])
         self.assertEqual(opts, [('-a', '')])

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Fri Dec  5 10:23:14 2008
@@ -60,6 +60,9 @@
 Library
 -------
 
+- Issue #4458: getopt.gnu_getopt() now recognizes a single "-" as an argument,
+  not a malformed option.
+
 - Added the subprocess.check_output() convenience function to get output
   from a subprocess on success or raise an exception on error.
 


More information about the Python-checkins mailing list