[Python-checkins] (no subject)

Batuhan Taşkaya webhook-mailer at python.org
Wed Mar 4 11:16:55 EST 2020




To: python-checkins at python.org
Subject: bpo-39639: Remove the AST "Suite" node and associated code (GH-18513)
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

https://github.com/python/cpython/commit/d82e469048e0e034d8c0020cd33b733be1ad=
f68b
commit: d82e469048e0e034d8c0020cd33b733be1adf68b
branch: master
author: Batuhan Ta=C5=9Fkaya <47358913+isidentical at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-03-04T16:16:46Z
summary:

bpo-39639: Remove the AST "Suite" node and associated code (GH-18513)

The AST "Suite" node is no longer used and it can be removed from the ASDL de=
finition and related structures (compiler, visitors, ...).

Co-Authored-By: Victor Stinner <vstinner at python.org>
Co-authored-by: Brett Cannon <54418+brettcannon at users.noreply.github.com>
Co-authored-by: Pablo Galindo <Pablogsal at gmail.com>

files:
A Misc/NEWS.d/next/Core and Builtins/2020-02-15-15-29-34.bpo-39639.3mqJjm.rst
M Doc/whatsnew/3.9.rst
M Include/Python-ast.h
M Lib/test/test_asdl_parser.py
M Parser/Python.asdl
M Python/Python-ast.c
M Python/ast.c
M Python/ast_opt.c
M Python/compile.c
M Python/symtable.c

diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst
index f15805c794ea8..d072b8db311cf 100644
--- a/Doc/whatsnew/3.9.rst
+++ b/Doc/whatsnew/3.9.rst
@@ -611,6 +611,9 @@ Removed
   defining ``COUNT_ALLOCS`` macro.
   (Contributed by Victor Stinner in :issue:`39489`.)
=20
+* The ``ast.Suite`` node class has been removed due to no longer being neede=
d.
+  (Contributed by Batuhan Taskaya in :issue:`39639`.)
+
=20
 Porting to Python 3.9
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
diff --git a/Include/Python-ast.h b/Include/Python-ast.h
index b9232b1d46307..931a6b945b472 100644
--- a/Include/Python-ast.h
+++ b/Include/Python-ast.h
@@ -51,7 +51,7 @@ typedef struct _type_ignore *type_ignore_ty;
=20
=20
 enum _mod_kind {Module_kind=3D1, Interactive_kind=3D2, Expression_kind=3D3,
-                 FunctionType_kind=3D4, Suite_kind=3D5};
+                 FunctionType_kind=3D4};
 struct _mod {
     enum _mod_kind kind;
     union {
@@ -73,10 +73,6 @@ struct _mod {
             expr_ty returns;
         } FunctionType;
=20
-        struct {
-            asdl_seq *body;
-        } Suite;
-
     } v;
 };
=20
@@ -483,8 +479,6 @@ mod_ty _Py_Interactive(asdl_seq * body, PyArena *arena);
 mod_ty _Py_Expression(expr_ty body, PyArena *arena);
 #define FunctionType(a0, a1, a2) _Py_FunctionType(a0, a1, a2)
 mod_ty _Py_FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena=
);
-#define Suite(a0, a1) _Py_Suite(a0, a1)
-mod_ty _Py_Suite(asdl_seq * body, PyArena *arena);
 #define FunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) _Py_Functio=
nDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
 stmt_ty _Py_FunctionDef(identifier name, arguments_ty args, asdl_seq * body,
                         asdl_seq * decorator_list, expr_ty returns, string
diff --git a/Lib/test/test_asdl_parser.py b/Lib/test/test_asdl_parser.py
index 9eaceecd50dbc..d3306c22184c5 100644
--- a/Lib/test/test_asdl_parser.py
+++ b/Lib/test/test_asdl_parser.py
@@ -118,7 +118,7 @@ def visitConstructor(self, cons):
         v =3D CustomVisitor()
         v.visit(self.types['mod'])
         self.assertEqual(v.names_with_seq,
-                         ['Module', 'Module', 'Interactive', 'FunctionType',=
 'Suite'])
+                         ['Module', 'Module', 'Interactive', 'FunctionType'])
=20
=20
 if __name__ =3D=3D '__main__':
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-02-15-15-29-34.bpo-39639=
.3mqJjm.rst b/Misc/NEWS.d/next/Core and Builtins/2020-02-15-15-29-34.bpo-3963=
9.3mqJjm.rst
new file mode 100644
index 0000000000000..7a54dd09b9e7f
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2020-02-15-15-29-34.bpo-39639.3mqJjm=
.rst=09
@@ -0,0 +1 @@
+Remove ``ast.Suite`` node class because it's no longer used. Patch by Batuha=
n Taskaya.
diff --git a/Parser/Python.asdl b/Parser/Python.asdl
index 126d478975bbb..bec30a7a1f311 100644
--- a/Parser/Python.asdl
+++ b/Parser/Python.asdl
@@ -3,14 +3,11 @@
=20
 module Python
 {
-    mod =3D Module(stmt* body, type_ignore *type_ignores)
+    mod =3D Module(stmt* body, type_ignore* type_ignores)
         | Interactive(stmt* body)
         | Expression(expr body)
         | FunctionType(expr* argtypes, expr returns)
=20
-        -- not really an actual node but useful in Jython's typesystem.
-        | Suite(stmt* body)
-
     stmt =3D FunctionDef(identifier name, arguments args,
                        stmt* body, expr* decorator_list, expr? returns,
                        string? type_comment)
@@ -51,7 +48,6 @@ module Python
           | Expr(expr value)
           | Pass | Break | Continue
=20
-          -- 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)
=20
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index e9925e742e733..2784c427d72dc 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -127,7 +127,6 @@ typedef struct {
     PyObject *Sub_singleton;
     PyObject *Sub_type;
     PyObject *Subscript_type;
-    PyObject *Suite_type;
     PyObject *Try_type;
     PyObject *Tuple_type;
     PyObject *TypeIgnore_type;
@@ -357,7 +356,6 @@ static int astmodule_clear(PyObject *module)
     Py_CLEAR(astmodulestate(module)->Sub_singleton);
     Py_CLEAR(astmodulestate(module)->Sub_type);
     Py_CLEAR(astmodulestate(module)->Subscript_type);
-    Py_CLEAR(astmodulestate(module)->Suite_type);
     Py_CLEAR(astmodulestate(module)->Try_type);
     Py_CLEAR(astmodulestate(module)->Tuple_type);
     Py_CLEAR(astmodulestate(module)->TypeIgnore_type);
@@ -586,7 +584,6 @@ static int astmodule_traverse(PyObject *module, visitproc=
 visit, void* arg)
     Py_VISIT(astmodulestate(module)->Sub_singleton);
     Py_VISIT(astmodulestate(module)->Sub_type);
     Py_VISIT(astmodulestate(module)->Subscript_type);
-    Py_VISIT(astmodulestate(module)->Suite_type);
     Py_VISIT(astmodulestate(module)->Try_type);
     Py_VISIT(astmodulestate(module)->Tuple_type);
     Py_VISIT(astmodulestate(module)->TypeIgnore_type);
@@ -807,9 +804,6 @@ static const char * const FunctionType_fields[]=3D{
     "argtypes",
     "returns",
 };
-static const char * const Suite_fields[]=3D{
-    "body",
-};
 static const char * const stmt_attributes[] =3D {
     "lineno",
     "col_offset",
@@ -1442,8 +1436,6 @@ static int init_types(void)
     state->FunctionType_type =3D make_type("FunctionType", state->mod_type,
                                          FunctionType_fields, 2);
     if (!state->FunctionType_type) return 0;
-    state->Suite_type =3D make_type("Suite", state->mod_type, Suite_fields, =
1);
-    if (!state->Suite_type) return 0;
     state->stmt_type =3D make_type("stmt", state->AST_type, NULL, 0);
     if (!state->stmt_type) return 0;
     if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0;
@@ -1920,18 +1912,6 @@ FunctionType(asdl_seq * argtypes, expr_ty returns, PyA=
rena *arena)
     return p;
 }
=20
-mod_ty
-Suite(asdl_seq * body, PyArena *arena)
-{
-    mod_ty p;
-    p =3D (mod_ty)PyArena_Malloc(arena, sizeof(*p));
-    if (!p)
-        return NULL;
-    p->kind =3D Suite_kind;
-    p->v.Suite.body =3D body;
-    return p;
-}
-
 stmt_ty
 FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
             decorator_list, expr_ty returns, string type_comment, int lineno,
@@ -3416,16 +3396,6 @@ ast2obj_mod(void* _o)
             goto failed;
         Py_DECREF(value);
         break;
-    case Suite_kind:
-        tp =3D (PyTypeObject *)astmodulestate_global->Suite_type;
-        result =3D PyType_GenericNew(tp, NULL, NULL);
-        if (!result) goto failed;
-        value =3D ast2obj_list(o->v.Suite.body, ast2obj_stmt);
-        if (!value) goto failed;
-        if (PyObject_SetAttr(result, astmodulestate_global->body, value) =3D=
=3D -1)
-            goto failed;
-        Py_DECREF(value);
-        break;
     }
     return result;
 failed:
@@ -5201,51 +5171,6 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
         if (*out =3D=3D NULL) goto failed;
         return 0;
     }
-    tp =3D astmodulestate_global->Suite_type;
-    isinstance =3D PyObject_IsInstance(obj, tp);
-    if (isinstance =3D=3D -1) {
-        return 1;
-    }
-    if (isinstance) {
-        asdl_seq* body;
-
-        if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0=
) {
-            return 1;
-        }
-        if (tmp =3D=3D NULL) {
-            PyErr_SetString(PyExc_TypeError, "required field \"body\" missin=
g from Suite");
-            return 1;
-        }
-        else {
-            int res;
-            Py_ssize_t len;
-            Py_ssize_t i;
-            if (!PyList_Check(tmp)) {
-                PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be =
a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
-                goto failed;
-            }
-            len =3D PyList_GET_SIZE(tmp);
-            body =3D _Py_asdl_seq_new(len, arena);
-            if (body =3D=3D NULL) goto failed;
-            for (i =3D 0; i < len; i++) {
-                stmt_ty val;
-                PyObject *tmp2 =3D PyList_GET_ITEM(tmp, i);
-                Py_INCREF(tmp2);
-                res =3D obj2ast_stmt(tmp2, &val, arena);
-                Py_DECREF(tmp2);
-                if (res !=3D 0) goto failed;
-                if (len !=3D PyList_GET_SIZE(tmp)) {
-                    PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\=
" changed size during iteration");
-                    goto failed;
-                }
-                asdl_seq_SET(body, i, val);
-            }
-            Py_CLEAR(tmp);
-        }
-        *out =3D Suite(body, arena);
-        if (*out =3D=3D NULL) goto failed;
-        return 0;
-    }
=20
     PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", o=
bj);
     failed:
@@ -9924,10 +9849,6 @@ PyInit__ast(void)
         goto error;
     }
     Py_INCREF(astmodulestate(m)->FunctionType_type);
-    if (PyModule_AddObject(m, "Suite", astmodulestate_global->Suite_type) < =
0) {
-        goto error;
-    }
-    Py_INCREF(astmodulestate(m)->Suite_type);
     if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0)=
 {
         goto error;
     }
diff --git a/Python/ast.c b/Python/ast.c
index 0aed54c8fe2ea..43b50c5dd4cc2 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -545,9 +545,6 @@ PyAST_Validate(mod_ty mod)
     case Expression_kind:
         res =3D 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 =3D 0;
diff --git a/Python/ast_opt.c b/Python/ast_opt.c
index f2a2c25914993..39e164adb8c94 100644
--- a/Python/ast_opt.c
+++ b/Python/ast_opt.c
@@ -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;
     }
diff --git a/Python/compile.c b/Python/compile.c
index bf8c8109d0758..f603e3d29e539 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1862,10 +1862,6 @@ compiler_mod(struct compiler *c, mod_ty mod)
         VISIT_IN_SCOPE(c, expr, mod->v.Expression.body);
         addNone =3D 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",
diff --git a/Python/symtable.c b/Python/symtable.c
index 30482d99b3ca9..a98a0fa6092cc 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -318,10 +318,6 @@ PySymtable_BuildObject(mod_ty mod, PyObject *filename, P=
yFutureFeatures *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");



More information about the Python-checkins mailing list