summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-11-24 18:24:47 (GMT)
committerGuido van Rossum <guido@python.org>2001-11-24 18:24:47 (GMT)
commit64585f6afb33ea907a22a365b4fdbec155e3da55 (patch)
tree9e0a109ee0bc1b1a7177a006b49717059d97ddf2
parentbf7c52c233485b0d95c3a41cb5ae9b580c4469c8 (diff)
downloadcpython-64585f6afb33ea907a22a365b4fdbec155e3da55.zip
cpython-64585f6afb33ea907a22a365b4fdbec155e3da55.tar.gz
cpython-64585f6afb33ea907a22a365b4fdbec155e3da55.tar.bz2
PyObject_GetItem(), PyObject_SetItem(), PyObject_DelItem(): Fix a few
confusing error messages. If a new-style class has no sequence or mapping behavior, attempting to use the indexing notation with a non-integer key would complain that the sequence index must be an integer, rather than complaining that the operation is not supported.
-rw-r--r--Objects/abstract.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 0856f19..5931449 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -103,7 +103,8 @@ PyObject_GetItem(PyObject *o, PyObject *key)
return NULL;
return PySequence_GetItem(o, key_value);
}
- return type_error("sequence index must be integer");
+ else if (o->ob_type->tp_as_sequence->sq_item)
+ return type_error("sequence index must be integer");
}
return type_error("unsubscriptable object");
@@ -131,8 +132,10 @@ PyObject_SetItem(PyObject *o, PyObject *key, PyObject *value)
return -1;
return PySequence_SetItem(o, key_value, value);
}
- type_error("sequence index must be integer");
- return -1;
+ else if (o->ob_type->tp_as_sequence->sq_ass_item) {
+ type_error("sequence index must be integer");
+ return -1;
+ }
}
type_error("object does not support item assignment");
@@ -161,8 +164,10 @@ PyObject_DelItem(PyObject *o, PyObject *key)
return -1;
return PySequence_DelItem(o, key_value);
}
- type_error("sequence index must be integer");
- return -1;
+ else if (o->ob_type->tp_as_sequence->sq_ass_item) {
+ type_error("sequence index must be integer");
+ return -1;
+ }
}
type_error("object does not support item deletion");