Skip to content

Commit

Permalink
bpo-39639: Remove the AST "Suite" node and associated code (GH-18513)
Browse files Browse the repository at this point in the history
The AST "Suite" node is no longer used and it can be removed from the ASDL definition and related structures (compiler, visitors, ...).

Co-Authored-By: Victor Stinner <vstinner@python.org>
Co-authored-by: Brett Cannon <54418+brettcannon@users.noreply.github.com>
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
  • Loading branch information
4 people committed Mar 4, 2020
1 parent 702e09f commit d82e469
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 106 deletions.
3 changes: 3 additions & 0 deletions Doc/whatsnew/3.9.rst
Expand Up @@ -611,6 +611,9 @@ Removed
defining ``COUNT_ALLOCS`` macro.
(Contributed by Victor Stinner in :issue:`39489`.)

* The ``ast.Suite`` node class has been removed due to no longer being needed.
(Contributed by Batuhan Taskaya in :issue:`39639`.)


Porting to Python 3.9
=====================
Expand Down
8 changes: 1 addition & 7 deletions Include/Python-ast.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Lib/test/test_asdl_parser.py
Expand Up @@ -118,7 +118,7 @@ def visitConstructor(self, cons):
v = CustomVisitor()
v.visit(self.types['mod'])
self.assertEqual(v.names_with_seq,
['Module', 'Module', 'Interactive', 'FunctionType', 'Suite'])
['Module', 'Module', 'Interactive', 'FunctionType'])


if __name__ == '__main__':
Expand Down
@@ -0,0 +1 @@
Remove ``ast.Suite`` node class because it's no longer used. Patch by Batuhan Taskaya.
6 changes: 1 addition & 5 deletions Parser/Python.asdl
Expand Up @@ -3,14 +3,11 @@

module Python
{
mod = Module(stmt* body, type_ignore *type_ignores)
mod = Module(stmt* body, type_ignore* type_ignores)
| Interactive(stmt* body)
| Expression(expr body)
| FunctionType(expr* argtypes, expr returns)

-- not really an actual node but useful in Jython's typesystem.
| Suite(stmt* body)

stmt = FunctionDef(identifier name, arguments args,
stmt* body, expr* decorator_list, expr? returns,
string? type_comment)
Expand Down Expand Up @@ -51,7 +48,6 @@ module Python
| Expr(expr value)
| Pass | Break | Continue

-- XXX Jython will be different
-- col_offset is the byte offset in the utf8 string the parser uses
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)

Expand Down
79 changes: 0 additions & 79 deletions Python/Python-ast.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Python/ast.c
Expand Up @@ -545,9 +545,6 @@ PyAST_Validate(mod_ty mod)
case Expression_kind:
res = validate_expr(mod->v.Expression.body, Load);
break;
case Suite_kind:
PyErr_SetString(PyExc_ValueError, "Suite is not valid in the CPython compiler");
break;
default:
PyErr_SetString(PyExc_SystemError, "impossible module node");
res = 0;
Expand Down
3 changes: 0 additions & 3 deletions Python/ast_opt.c
Expand Up @@ -462,9 +462,6 @@ astfold_mod(mod_ty node_, PyArena *ctx_, int optimize_)
case Expression_kind:
CALL(astfold_expr, expr_ty, node_->v.Expression.body);
break;
case Suite_kind:
CALL_SEQ(astfold_stmt, stmt_ty, node_->v.Suite.body);
break;
default:
break;
}
Expand Down
4 changes: 0 additions & 4 deletions Python/compile.c
Expand Up @@ -1862,10 +1862,6 @@ compiler_mod(struct compiler *c, mod_ty mod)
VISIT_IN_SCOPE(c, expr, mod->v.Expression.body);
addNone = 0;
break;
case Suite_kind:
PyErr_SetString(PyExc_SystemError,
"suite should not be possible");
return 0;
default:
PyErr_Format(PyExc_SystemError,
"module kind %d should not be possible",
Expand Down
4 changes: 0 additions & 4 deletions Python/symtable.c
Expand Up @@ -318,10 +318,6 @@ PySymtable_BuildObject(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
(stmt_ty)asdl_seq_GET(seq, i)))
goto error;
break;
case Suite_kind:
PyErr_SetString(PyExc_RuntimeError,
"this compiler does not handle Suites");
goto error;
case FunctionType_kind:
PyErr_SetString(PyExc_RuntimeError,
"this compiler does not handle FunctionTypes");
Expand Down

0 comments on commit d82e469

Please sign in to comment.