From: Benjamin Peterson Date: Sun, 5 Jun 2011 03:06:42 +0000 (-0500) Subject: only clear the parser error if it's set (closes #12264) X-Git-Tag: v3.3.0a1~2183^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f719957d7a1f8ee1545e7b5bd3f59aa24e6db5fc;p=python only clear the parser error if it's set (closes #12264) --- diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py index 020acd500f..2b50fca818 100644 --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -614,6 +614,13 @@ class STObjectTestCase(unittest.TestCase): # XXX tests for pickling and unpickling of ST objects should go here +class OtherParserCase(unittest.TestCase): + + def test_two_args_to_expr(self): + # See bug #12264 + with self.assertRaises(TypeError): + parser.expr("a", "b") + def test_main(): support.run_unittest( @@ -622,6 +629,7 @@ def test_main(): CompileTestCase, ParserStackLimitTestCase, STObjectTestCase, + OtherParserCase, ) diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index e5b4e55943..1ffa8963ff 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -581,10 +581,11 @@ parser_do_parse(PyObject *args, PyObject *kw, char *argspec, int type) if (res) ((PyST_Object *)res)->st_flags.cf_flags = flags & PyCF_MASK; } - else + else { PyParser_SetError(&err); + PyParser_ClearError(&err); + } } - PyParser_ClearError(&err); return (res); }