From: Victor Stinner Date: Sat, 24 Jul 2010 00:49:20 +0000 (+0000) Subject: Issue #4629: getopt raises an error if an argument ends with = whereas getopt X-Git-Tag: v3.2a1~117 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eccc5facd34609c029efce6fd2cd302f73e50566;p=python 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). --- diff --git a/Lib/getopt.py b/Lib/getopt.py index 13ef4d623e..ac77126acf 100644 --- a/Lib/getopt.py +++ b/Lib/getopt.py @@ -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 diff --git a/Lib/test/test_getopt.py b/Lib/test/test_getopt.py index 13e1980251..a265b6b08a 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 c06ac1f915..295a9a7e73 100644 --- 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.