mirror of https://github.com/python/cpython
#4396 make the parser module correctly validate the with syntax
This commit is contained in:
parent
39ff59e577
commit
9dfe6a8862
|
@ -196,6 +196,10 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
|
||||||
def test_assert(self):
|
def test_assert(self):
|
||||||
self.check_suite("assert alo < ahi and blo < bhi\n")
|
self.check_suite("assert alo < ahi and blo < bhi\n")
|
||||||
|
|
||||||
|
def test_with(self):
|
||||||
|
self.check_suite("with open('x'): pass\n")
|
||||||
|
self.check_suite("with open('x') as f: pass\n")
|
||||||
|
|
||||||
def test_position(self):
|
def test_position(self):
|
||||||
# An absolutely minimal test of position information. Better
|
# An absolutely minimal test of position information. Better
|
||||||
# tests would be a big project.
|
# tests would be a big project.
|
||||||
|
|
|
@ -106,6 +106,11 @@ C-API
|
||||||
- Issue #4122: On Windows, fix a compilation error when using the
|
- Issue #4122: On Windows, fix a compilation error when using the
|
||||||
Py_UNICODE_ISSPACE macro in an extension module.
|
Py_UNICODE_ISSPACE macro in an extension module.
|
||||||
|
|
||||||
|
Extension Modules
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
- Issue #4396: The parser module now correctly validates the with statement.
|
||||||
|
|
||||||
|
|
||||||
What's New in Python 2.6 final
|
What's New in Python 2.6 final
|
||||||
==============================
|
==============================
|
||||||
|
|
|
@ -1559,7 +1559,7 @@ validate_small_stmt(node *tree)
|
||||||
|
|
||||||
|
|
||||||
/* compound_stmt:
|
/* compound_stmt:
|
||||||
* if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef | decorated
|
* if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
validate_compound_stmt(node *tree)
|
validate_compound_stmt(node *tree)
|
||||||
|
@ -1577,6 +1577,7 @@ validate_compound_stmt(node *tree)
|
||||||
|| (ntype == while_stmt)
|
|| (ntype == while_stmt)
|
||||||
|| (ntype == for_stmt)
|
|| (ntype == for_stmt)
|
||||||
|| (ntype == try_stmt)
|
|| (ntype == try_stmt)
|
||||||
|
|| (ntype == with_stmt)
|
||||||
|| (ntype == funcdef)
|
|| (ntype == funcdef)
|
||||||
|| (ntype == classdef)
|
|| (ntype == classdef)
|
||||||
|| (ntype == decorated))
|
|| (ntype == decorated))
|
||||||
|
@ -2617,6 +2618,38 @@ validate_decorators(node *tree)
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* with_var
|
||||||
|
with_var: 'as' expr
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
validate_with_var(node *tree)
|
||||||
|
{
|
||||||
|
int nch = NCH(tree);
|
||||||
|
int ok = (validate_ntype(tree, with_var)
|
||||||
|
&& (nch == 2)
|
||||||
|
&& validate_name(CHILD(tree, 0), "as")
|
||||||
|
&& validate_expr(CHILD(tree, 1)));
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* with_stmt
|
||||||
|
* 0 1 2 -2 -1
|
||||||
|
with_stmt: 'with' test [ with_var ] ':' suite
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
validate_with_stmt(node *tree)
|
||||||
|
{
|
||||||
|
int nch = NCH(tree);
|
||||||
|
int ok = (validate_ntype(tree, with_stmt)
|
||||||
|
&& ((nch == 4) || (nch == 5))
|
||||||
|
&& validate_name(CHILD(tree, 0), "with")
|
||||||
|
&& validate_test(CHILD(tree, 1))
|
||||||
|
&& (nch == 4 || validate_with_var(CHILD(tree, 2)))
|
||||||
|
&& validate_colon(RCHILD(tree, -2))
|
||||||
|
&& validate_suite(RCHILD(tree, -1)));
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
/* funcdef:
|
/* funcdef:
|
||||||
*
|
*
|
||||||
* -5 -4 -3 -2 -1
|
* -5 -4 -3 -2 -1
|
||||||
|
@ -2993,6 +3026,9 @@ validate_node(node *tree)
|
||||||
case funcdef:
|
case funcdef:
|
||||||
res = validate_funcdef(tree);
|
res = validate_funcdef(tree);
|
||||||
break;
|
break;
|
||||||
|
case with_stmt:
|
||||||
|
res = validate_with_stmt(tree);
|
||||||
|
break;
|
||||||
case classdef:
|
case classdef:
|
||||||
res = validate_class(tree);
|
res = validate_class(tree);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue