]> granicus.if.org Git - python/commitdiff
Merged revisions 83116 via svnmerge from
authorVictor Stinner <victor.stinner@haypocalc.com>
Sat, 24 Jul 2010 01:07:52 +0000 (01:07 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Sat, 24 Jul 2010 01:07:52 +0000 (01:07 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r83116 | victor.stinner | 2010-07-24 02:49:20 +0200 (sam., 24 juil. 2010) | 4 lines

  Issue #4629: getopt raises an error if an argument ends with = whereas getopt
  doesn't except a value (eg. --help= is rejected if getopt uses ['help='] long
  options).
........

Lib/getopt.py
Lib/test/test_getopt.py
Misc/NEWS

index 66f48273c46fb62f1a149eaee264eb9bfef7d3f5..251d89c5cfe9ad9c11768377c86140243d9f92ee 100644 (file)
@@ -155,7 +155,7 @@ def do_longs(opts, opt, longopts, args):
             if not args:
                 raise GetoptError('option --%s requires argument' % opt, opt)
             optarg, args = args[0], args[1:]
-    elif optarg:
+    elif optarg is not None:
         raise GetoptError('option --%s must not have an argument' % opt, opt)
     opts.append(('--' + opt, optarg or ''))
     return opts, args
index 6b18d9f1d1a476839d5518aced3f994f42901850..7186c7f26e59b4b4619a3aed647381ce4f02f955 100644 (file)
@@ -173,6 +173,12 @@ class GetoptTests(unittest.TestCase):
         m = types.ModuleType("libreftest", s)
         run_doctest(m, verbose)
 
+    def test_issue4629(self):
+        longopts, shortopts = getopt.getopt(['--help='], '', ['help='])
+        self.assertEquals(longopts, [('--help', '')])
+        longopts, shortopts = getopt.getopt(['--help=x'], '', ['help='])
+        self.assertEquals(longopts, [('--help', 'x')])
+        self.assertRaises(getopt.GetoptError, getopt.getopt, ['--help='], '', ['help'])
 
 def test_main():
     run_unittest(GetoptTests)
index 8c18da4e6f61e3ce6dc32d8d60a6e178eaaa771f..e1f2c20a8666b14f08cf7ea58b88f37719d9819b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -18,6 +18,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #4629: getopt raises an error if an argument ends with = whereas getopt
+  doesn't except a value (eg. --help= is rejected if getopt uses ['help='] long
+  options).
+
 - Issue #7895: platform.mac_ver() no longer crashes after calling os.fork()
 
 - Issue #5395: array.fromfile() would raise a spurious EOFError when an