mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #27352: Correct the validation of the ImportFrom AST node and simplify
the implementation of the IMPORT_NAME opcode.
This commit is contained in:
parent
44a98b6bf3
commit
fbd1523525
2 changed files with 3 additions and 11 deletions
|
@ -475,8 +475,8 @@ validate_stmt(stmt_ty stmt)
|
||||||
case Import_kind:
|
case Import_kind:
|
||||||
return validate_nonempty_seq(stmt->v.Import.names, "names", "Import");
|
return validate_nonempty_seq(stmt->v.Import.names, "names", "Import");
|
||||||
case ImportFrom_kind:
|
case ImportFrom_kind:
|
||||||
if (stmt->v.ImportFrom.level < -1) {
|
if (stmt->v.ImportFrom.level < 0) {
|
||||||
PyErr_SetString(PyExc_ValueError, "ImportFrom level less than -1");
|
PyErr_SetString(PyExc_ValueError, "Negative ImportFrom level");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return validate_nonempty_seq(stmt->v.ImportFrom.names, "names", "ImportFrom");
|
return validate_nonempty_seq(stmt->v.ImportFrom.names, "names", "ImportFrom");
|
||||||
|
|
|
@ -2820,7 +2820,6 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
|
||||||
Py_INCREF(func);
|
Py_INCREF(func);
|
||||||
from = POP();
|
from = POP();
|
||||||
level = TOP();
|
level = TOP();
|
||||||
if (PyLong_AsLong(level) != -1 || PyErr_Occurred())
|
|
||||||
args = PyTuple_Pack(5,
|
args = PyTuple_Pack(5,
|
||||||
name,
|
name,
|
||||||
f->f_globals,
|
f->f_globals,
|
||||||
|
@ -2828,13 +2827,6 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
|
||||||
Py_None : f->f_locals,
|
Py_None : f->f_locals,
|
||||||
from,
|
from,
|
||||||
level);
|
level);
|
||||||
else
|
|
||||||
args = PyTuple_Pack(4,
|
|
||||||
name,
|
|
||||||
f->f_globals,
|
|
||||||
f->f_locals == NULL ?
|
|
||||||
Py_None : f->f_locals,
|
|
||||||
from);
|
|
||||||
Py_DECREF(level);
|
Py_DECREF(level);
|
||||||
Py_DECREF(from);
|
Py_DECREF(from);
|
||||||
if (args == NULL) {
|
if (args == NULL) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue