From ffa0d95c55f56a5c966251cbced8b2e966aab5ed Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Thu, 19 May 2022 13:41:36 -0700 Subject: [PATCH 1/2] gh-92986: Make level of ImportFrom not optional on ASDL --- Parser/Python.asdl | 2 +- Python/Python-ast.c | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Parser/Python.asdl b/Parser/Python.asdl index e9423a7c984f21..e1837e3341c0e8 100644 --- a/Parser/Python.asdl +++ b/Parser/Python.asdl @@ -44,7 +44,7 @@ module Python | Assert(expr test, expr? msg) | Import(alias* names) - | ImportFrom(identifier? module, alias* names, int? level) + | ImportFrom(identifier? module, alias* names, int level) | Global(identifier* names) | Nonlocal(identifier* names) diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 3861eaf978a38f..d618ab2c009482 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -1150,7 +1150,7 @@ init_types(struct ast_state *state) " | TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n" " | Assert(expr test, expr? msg)\n" " | Import(alias* names)\n" - " | ImportFrom(identifier? module, alias* names, int? level)\n" + " | ImportFrom(identifier? module, alias* names, int level)\n" " | Global(identifier* names)\n" " | Nonlocal(identifier* names)\n" " | Expr(expr value)\n" @@ -1279,12 +1279,10 @@ init_types(struct ast_state *state) if (!state->Import_type) return 0; state->ImportFrom_type = make_type(state, "ImportFrom", state->stmt_type, ImportFrom_fields, 3, - "ImportFrom(identifier? module, alias* names, int? level)"); + "ImportFrom(identifier? module, alias* names, int level)"); if (!state->ImportFrom_type) return 0; if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1) return 0; - if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1) - return 0; state->Global_type = make_type(state, "Global", state->stmt_type, Global_fields, 1, "Global(identifier* names)"); @@ -7866,9 +7864,9 @@ obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena* if (_PyObject_LookupAttr(obj, state->level, &tmp) < 0) { return 1; } - if (tmp == NULL || tmp == Py_None) { - Py_CLEAR(tmp); - level = 0; + if (tmp == NULL) { + PyErr_SetString(PyExc_TypeError, "required field \"level\" missing from ImportFrom"); + return 1; } else { int res; From 0a62a7175ac0a62be43abe5123b83dcc4bb34928 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 19 May 2022 20:51:32 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022-05-19-20-51-30.gh-issue-92986.YZod_o.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-05-19-20-51-30.gh-issue-92986.YZod_o.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-05-19-20-51-30.gh-issue-92986.YZod_o.rst b/Misc/NEWS.d/next/Core and Builtins/2022-05-19-20-51-30.gh-issue-92986.YZod_o.rst new file mode 100644 index 00000000000000..20c16863af1630 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-05-19-20-51-30.gh-issue-92986.YZod_o.rst @@ -0,0 +1,2 @@ +ASDL declaration of ``ImportFrom`` has changed to reflect ``level`` +field is not optional.