diff options
Diffstat (limited to 'Lib')
| -rw-r--r-- | Lib/getopt.py | 2 | ||||
| -rw-r--r-- | Lib/test/test_getopt.py | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/Lib/getopt.py b/Lib/getopt.py index 04e881e..f76d3de 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 36d1688..4967388 100644 --- a/Lib/test/test_getopt.py +++ b/Lib/test/test_getopt.py @@ -171,6 +171,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) |
