]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39969: Remove ast.Param node class as is no longer used (GH-19020)
authorBatuhan Taşkaya <47358913+isidentical@users.noreply.github.com>
Sun, 15 Mar 2020 19:32:17 +0000 (22:32 +0300)
committerGitHub <noreply@github.com>
Sun, 15 Mar 2020 19:32:17 +0000 (19:32 +0000)
Doc/whatsnew/3.9.rst
Include/Python-ast.h
Misc/NEWS.d/next/Library/2020-03-15-17-56-48.bpo-39969.6snm0c.rst [new file with mode: 0644]
Parser/Python.asdl
Python/Python-ast.c
Python/ast.c
Python/compile.c

index 12e3f18408d4fe7142c229add7fa99db94ede462..1d462c21987c1d74c9436f04cd82eb34bd2ad279 100644 (file)
@@ -664,8 +664,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`.)
+* The ``ast.Suite`` and ``ast.Param`` node classes has been removed due to no
+  longer being needed.
+  (Contributed by Batuhan Taskaya in :issue:`39639` and :issue:`39969`.)
 
 
 Porting to Python 3.9
index f4631f2f9b5d1cdbe115fb5d6d9a32ebf3c29ac2..c44d6ea3fea0f6edfc044fb83aa32d04b9310f10 100644 (file)
@@ -17,8 +17,8 @@ typedef struct _stmt *stmt_ty;
 
 typedef struct _expr *expr_ty;
 
-typedef enum _expr_context { Load=1, Store=2, Del=3, AugLoad=4, AugStore=5,
-                             Param=6 } expr_context_ty;
+typedef enum _expr_context { Load=1, Store=2, Del=3, AugLoad=4, AugStore=5 }
+                             expr_context_ty;
 
 typedef enum _boolop { And=1, Or=2 } boolop_ty;
 
diff --git a/Misc/NEWS.d/next/Library/2020-03-15-17-56-48.bpo-39969.6snm0c.rst b/Misc/NEWS.d/next/Library/2020-03-15-17-56-48.bpo-39969.6snm0c.rst
new file mode 100644 (file)
index 0000000..d584cf4
--- /dev/null
@@ -0,0 +1,2 @@
+Remove ``ast.Param`` node class because it's no longer used. Patch by
+Batuhan Taskaya.
index a1ddebdbcc772ca75b6a93694df62f2e84256e3a..19b5e1a15ab2127109f9975b356919517c1f9595 100644 (file)
@@ -90,7 +90,7 @@ module Python
           -- 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)
 
-    expr_context = Load | Store | Del | AugLoad | AugStore | Param
+    expr_context = Load | Store | Del | AugLoad | AugStore
 
     boolop = And | Or
 
index f58dd9c21787e2e5bf2de80161218574580b81eb..ed5aba655ec639b94e178ccef3190f0bd4ab0129 100644 (file)
@@ -107,8 +107,6 @@ typedef struct {
     PyObject *Not_type;
     PyObject *Or_singleton;
     PyObject *Or_type;
-    PyObject *Param_singleton;
-    PyObject *Param_type;
     PyObject *Pass_type;
     PyObject *Pow_singleton;
     PyObject *Pow_type;
@@ -332,8 +330,6 @@ static int astmodule_clear(PyObject *module)
     Py_CLEAR(astmodulestate(module)->Not_type);
     Py_CLEAR(astmodulestate(module)->Or_singleton);
     Py_CLEAR(astmodulestate(module)->Or_type);
-    Py_CLEAR(astmodulestate(module)->Param_singleton);
-    Py_CLEAR(astmodulestate(module)->Param_type);
     Py_CLEAR(astmodulestate(module)->Pass_type);
     Py_CLEAR(astmodulestate(module)->Pow_singleton);
     Py_CLEAR(astmodulestate(module)->Pow_type);
@@ -556,8 +552,6 @@ static int astmodule_traverse(PyObject *module, visitproc visit, void* arg)
     Py_VISIT(astmodulestate(module)->Not_type);
     Py_VISIT(astmodulestate(module)->Or_singleton);
     Py_VISIT(astmodulestate(module)->Or_type);
-    Py_VISIT(astmodulestate(module)->Param_singleton);
-    Py_VISIT(astmodulestate(module)->Param_type);
     Py_VISIT(astmodulestate(module)->Pass_type);
     Py_VISIT(astmodulestate(module)->Pow_singleton);
     Py_VISIT(astmodulestate(module)->Pow_type);
@@ -1656,11 +1650,6 @@ static int init_types(void)
                                                   *)state->AugStore_type, NULL,
                                                   NULL);
     if (!state->AugStore_singleton) return 0;
-    state->Param_type = make_type("Param", state->expr_context_type, NULL, 0);
-    if (!state->Param_type) return 0;
-    state->Param_singleton = PyType_GenericNew((PyTypeObject
-                                               *)state->Param_type, NULL, NULL);
-    if (!state->Param_singleton) return 0;
     state->boolop_type = make_type("boolop", state->AST_type, NULL, 0);
     if (!state->boolop_type) return 0;
     if (!add_attributes(state->boolop_type, NULL, 0)) return 0;
@@ -4474,9 +4463,6 @@ PyObject* ast2obj_expr_context(expr_context_ty o)
         case AugStore:
             Py_INCREF(astmodulestate_global->AugStore_singleton);
             return astmodulestate_global->AugStore_singleton;
-        case Param:
-            Py_INCREF(astmodulestate_global->Param_singleton);
-            return astmodulestate_global->Param_singleton;
         default:
             /* should never happen, but just in case ... */
             PyErr_Format(PyExc_SystemError, "unknown expr_context found");
@@ -8682,14 +8668,6 @@ obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
         *out = AugStore;
         return 0;
     }
-    isinstance = PyObject_IsInstance(obj, astmodulestate_global->Param_type);
-    if (isinstance == -1) {
-        return 1;
-    }
-    if (isinstance) {
-        *out = Param;
-        return 0;
-    }
 
     PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
     return 1;
@@ -10038,10 +10016,6 @@ PyInit__ast(void)
         goto error;
     }
     Py_INCREF(astmodulestate(m)->AugStore_type);
-    if (PyModule_AddObject(m, "Param", astmodulestate_global->Param_type) < 0) {
-        goto error;
-    }
-    Py_INCREF(astmodulestate(m)->Param_type);
     if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) <
         0) {
         goto error;
index 62ee60aa9ff6ceb60b25d7011f1c2b07ac29f373..1c1395f6f036d199a00a64f80dcaccfc0c8c432f 100644 (file)
@@ -75,8 +75,6 @@ expr_context_name(expr_context_ty ctx)
         return "AugLoad";
     case AugStore:
         return "AugStore";
-    case Param:
-        return "Param";
     default:
         Py_UNREACHABLE();
     }
index b92cb445afb4a9c44c7542746afd98bd6b09bd3f..dd14023fcc485e2472670220ffd9e23e4fb02547 100644 (file)
@@ -3579,10 +3579,10 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
         case AugStore:
             break;
         case Del: op = DELETE_DEREF; break;
-        case Param:
         default:
-            PyErr_SetString(PyExc_SystemError,
-                            "param invalid for deref variable");
+            PyErr_Format(PyExc_SystemError,
+                         "expr_context kind %d should not be possible",
+                         ctx);
             return 0;
         }
         break;
@@ -3596,10 +3596,10 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
         case AugLoad:
         case AugStore:
             break;
-        case Param:
         default:
-            PyErr_SetString(PyExc_SystemError,
-                            "param invalid for local variable");
+            PyErr_Format(PyExc_SystemError,
+                         "expr_context kind %d should not be possible",
+                         ctx);
             return 0;
         }
         ADDOP_N(c, op, mangled, varnames);
@@ -3614,10 +3614,10 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
         case AugLoad:
         case AugStore:
             break;
-        case Param:
         default:
-            PyErr_SetString(PyExc_SystemError,
-                            "param invalid for global variable");
+            PyErr_Format(PyExc_SystemError,
+                         "expr_context kind %d should not be possible",
+                         ctx);
             return 0;
         }
         break;
@@ -3631,10 +3631,10 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
         case AugLoad:
         case AugStore:
             break;
-        case Param:
         default:
-            PyErr_SetString(PyExc_SystemError,
-                            "param invalid for name variable");
+            PyErr_Format(PyExc_SystemError,
+                         "expr_context kind %d should not be possible",
+                         ctx);
             return 0;
         }
         break;
@@ -5058,10 +5058,10 @@ compiler_visit_expr1(struct compiler *c, expr_ty e)
         case Del:
             ADDOP_NAME(c, DELETE_ATTR, e->v.Attribute.attr, names);
             break;
-        case Param:
         default:
-            PyErr_SetString(PyExc_SystemError,
-                            "param invalid in attribute expression");
+            PyErr_Format(PyExc_SystemError,
+                         "expr_context kind %d should not be possible",
+                         e->v.Attribute.ctx);
             return 0;
         }
         break;
@@ -5359,9 +5359,10 @@ compiler_subscript(struct compiler *c, expr_ty e)
         case AugStore:/* fall through to Store */
         case Store:   op = STORE_SUBSCR; break;
         case Del:     op = DELETE_SUBSCR; break;
-        case Param:
-            PyErr_SetString(PyExc_SystemError,
-                "param invalid in subscript expression");
+        default:
+            PyErr_Format(PyExc_SystemError,
+                         "expr_context kind %d should not be possible",
+                         ctx);
             return 0;
     }
     if (ctx == AugStore) {