From 4c16d122c42494ac735d5417cd79c70d67d341e0 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 24 Jul 2010 01:07:52 +0000 Subject: [PATCH] Merged revisions 83116 via svnmerge from 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 | 2 +- Lib/test/test_getopt.py | 6 ++++++ Misc/NEWS | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Lib/getopt.py b/Lib/getopt.py index 66f48273c46..251d89c5cfe 100644 --- a/Lib/getopt.py +++ b/Lib/getopt.py @@ -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 diff --git a/Lib/test/test_getopt.py b/Lib/test/test_getopt.py index 6b18d9f1d1a..7186c7f26e5 100644 --- a/Lib/test/test_getopt.py +++ b/Lib/test/test_getopt.py @@ -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) diff --git a/Misc/NEWS b/Misc/NEWS index 8c18da4e6f6..e1f2c20a866 100644 --- 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