]> granicus.if.org Git - python/commitdiff
Issue #4629: getopt raises an error if an argument ends with = whereas getopt
authorVictor Stinner <victor.stinner@haypocalc.com>
Sat, 24 Jul 2010 00:49:20 +0000 (00:49 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Sat, 24 Jul 2010 00:49:20 +0000 (00:49 +0000)
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 13ef4d623ec0a12930789b18689847470ec63a13..ac77126acf2fa09d965f57d8346b46991f0960a9 100644 (file)
@@ -156,7 +156,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 13e1980251defab6110975835c54810120029c9f..a265b6b08abb0eccbe845abb979be6a827bf4482 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 c06ac1f9155fe6e85bd5c03f12464dccea56c8e9..295a9a7e732645f55ffd32f9fd16770f7b8fa6f0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -473,6 +473,10 @@ C-API
 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 #7989: Added pure python implementation of the `datetime`
   module.  The C module is renamed to `_datetime` and if available,
   overrides all classes defined in datetime with fast C impementation.