[Python-checkins] cpython: Issue #27352: Correct the validation of the ImportFrom AST node and simplify

serhiy.storchaka python-checkins at python.org
Mon Jun 27 14:39:36 EDT 2016


https://hg.python.org/cpython/rev/e3164c9edb0b
changeset: 102216:e3164c9edb0b
parent: 102214:aa1e1f7e17cc
user: Serhiy Storchaka <storchaka at gmail.com>
date: Mon Jun 27 21:39:12 2016 +0300
summary:
 Issue #27352: Correct the validation of the ImportFrom AST node and simplify
the implementation of the IMPORT_NAME opcode.
files:
 Python/ast.c | 4 ++--
 Python/ceval.c | 10 +---------
 2 files changed, 3 insertions(+), 11 deletions(-)
diff --git a/Python/ast.c b/Python/ast.c
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -475,8 +475,8 @@
 case Import_kind:
 return validate_nonempty_seq(stmt->v.Import.names, "names", "Import");
 case ImportFrom_kind:
- if (stmt->v.ImportFrom.level < -1) {
- PyErr_SetString(PyExc_ValueError, "ImportFrom level less than -1");
+ if (stmt->v.ImportFrom.level < 0) {
+ PyErr_SetString(PyExc_ValueError, "Negative ImportFrom level");
 return 0;
 }
 return validate_nonempty_seq(stmt->v.ImportFrom.names, "names", "ImportFrom");
diff --git a/Python/ceval.c b/Python/ceval.c
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -2820,21 +2820,13 @@
 Py_INCREF(func);
 from = POP();
 level = TOP();
- if (PyLong_AsLong(level) != -1 || PyErr_Occurred())
- args = PyTuple_Pack(5,
+ args = PyTuple_Pack(5,
 name,
 f->f_globals,
 f->f_locals == NULL ?
 Py_None : f->f_locals,
 from,
 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(from);
 if (args == NULL) {
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /