summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-12-24 13:25:19 (GMT)
committerGuido van Rossum <guido@python.org>1991-12-24 13:25:19 (GMT)
commit98256aa518d3317b03581246195eb572beb58a47 (patch)
treefca232685e122b0836eca5cc345b26cfd610e276 /Python/ceval.c
parented7711b7cb00cd2dfab52e9626f67632a3d75816 (diff)
downloadcpython-98256aa518d3317b03581246195eb572beb58a47.zip
cpython-98256aa518d3317b03581246195eb572beb58a47.tar.gz
cpython-98256aa518d3317b03581246195eb572beb58a47.tar.bz2
Negative subscript are now allowed as in slices.
Added ImportError.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 46da00b..ec24110 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1511,6 +1511,8 @@ apply_subscript(v, w)
return NULL;
}
i = getintvalue(w);
+ if (i < 0)
+ i += (*tp->tp_as_sequence->sq_length)(v);
return (*tp->tp_as_sequence->sq_item)(v, i);
}
return (*tp->tp_as_mapping->mp_subscript)(v, w);
@@ -1584,11 +1586,15 @@ assign_subscript(w, key, v) /* w[key] = v */
(func = sq->sq_ass_item) != NULL) {
if (!is_intobject(key)) {
err_setstr(TypeError,
- "sequence subscript must be integer");
+ "sequence subscript must be integer (assign or del)");
return -1;
}
- else
- return (*func)(w, (int)getintvalue(key), v);
+ else {
+ int i = getintvalue(key);
+ if (i < 0)
+ i += (*sq->sq_length)(v);
+ return (*func)(w, i, v);
+ }
}
else if ((mp = tp->tp_as_mapping) != NULL &&
(func = mp->mp_ass_subscript) != NULL) {
@@ -1726,8 +1732,6 @@ cmp_outcome(op, v, w)
return v;
}
-/* XXX This function should use dict2 variants (change interface!) */
-
static int
import_from(locals, v, name)
object *locals;
@@ -1746,7 +1750,7 @@ import_from(locals, v, name)
x = dict2lookup(w, name);
if (x == NULL) {
/* XXX can't happen? */
- err_setstr(NameError, getstringvalue(name));
+ err_setstr(SystemError, getstringvalue(name));
return -1;
}
if (dict2insert(locals, name, x) != 0)
@@ -1757,7 +1761,10 @@ import_from(locals, v, name)
else {
x = dict2lookup(w, name);
if (x == NULL) {
- err_setstr(NameError, getstringvalue(name));
+ char buf[250];
+ sprintf(buf, "cannot import name %s",
+ getstringvalue(name));
+ err_setstr(ImportError, buf);
return -1;
}
else