Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fbd1523

Browse files
Issue #27352: Correct the validation of the ImportFrom AST node and simplify
the implementation of the IMPORT_NAME opcode.
1 parent 44a98b6 commit fbd1523

2 files changed

Lines changed: 3 additions & 11 deletions

File tree

Python/ast.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,8 @@ validate_stmt(stmt_ty stmt)
475475
case Import_kind:
476476
return validate_nonempty_seq(stmt->v.Import.names, "names", "Import");
477477
case ImportFrom_kind:
478-
if (stmt->v.ImportFrom.level < -1) {
479-
PyErr_SetString(PyExc_ValueError, "ImportFrom level less than -1");
478+
if (stmt->v.ImportFrom.level < 0) {
479+
PyErr_SetString(PyExc_ValueError, "Negative ImportFrom level");
480480
return 0;
481481
}
482482
return validate_nonempty_seq(stmt->v.ImportFrom.names, "names", "ImportFrom");

Python/ceval.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,21 +2820,13 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
28202820
Py_INCREF(func);
28212821
from = POP();
28222822
level = TOP();
2823-
if (PyLong_AsLong(level) != -1 || PyErr_Occurred())
2824-
args = PyTuple_Pack(5,
2823+
args = PyTuple_Pack(5,
28252824
name,
28262825
f->f_globals,
28272826
f->f_locals == NULL ?
28282827
Py_None : f->f_locals,
28292828
from,
28302829
level);
2831-
else
2832-
args = PyTuple_Pack(4,
2833-
name,
2834-
f->f_globals,
2835-
f->f_locals == NULL ?
2836-
Py_None : f->f_locals,
2837-
from);
28382830
Py_DECREF(level);
28392831
Py_DECREF(from);
28402832
if (args == NULL) {

0 commit comments

Comments
 (0)