Commit 64585f6a authored by Guido van Rossum's avatar Guido van Rossum

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.
parent bf7c52c2
...@@ -103,7 +103,8 @@ PyObject_GetItem(PyObject *o, PyObject *key) ...@@ -103,7 +103,8 @@ PyObject_GetItem(PyObject *o, PyObject *key)
return NULL; return NULL;
return PySequence_GetItem(o, key_value); 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"); return type_error("unsubscriptable object");
...@@ -131,8 +132,10 @@ PyObject_SetItem(PyObject *o, PyObject *key, PyObject *value) ...@@ -131,8 +132,10 @@ PyObject_SetItem(PyObject *o, PyObject *key, PyObject *value)
return -1; return -1;
return PySequence_SetItem(o, key_value, value); return PySequence_SetItem(o, key_value, value);
} }
type_error("sequence index must be integer"); else if (o->ob_type->tp_as_sequence->sq_ass_item) {
return -1; type_error("sequence index must be integer");
return -1;
}
} }
type_error("object does not support item assignment"); type_error("object does not support item assignment");
...@@ -161,8 +164,10 @@ PyObject_DelItem(PyObject *o, PyObject *key) ...@@ -161,8 +164,10 @@ PyObject_DelItem(PyObject *o, PyObject *key)
return -1; return -1;
return PySequence_DelItem(o, key_value); return PySequence_DelItem(o, key_value);
} }
type_error("sequence index must be integer"); else if (o->ob_type->tp_as_sequence->sq_ass_item) {
return -1; type_error("sequence index must be integer");
return -1;
}
} }
type_error("object does not support item deletion"); type_error("object does not support item deletion");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment