summaryrefslogtreecommitdiff
path: root/Objects
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-02-17 15:33:04 -0800
committerGitHub <noreply@github.com>2019-02-17 15:33:04 -0800
commita7f929db605326da452fbdeebfe341afa9316d25 (patch)
tree56b8fb61a61df34a2820591d9b04f88126df921f /Objects
parent6f352199e4447764bc472e34352d0dff4db8a52d (diff)
downloadcpython-git-a7f929db605326da452fbdeebfe341afa9316d25.tar.gz
bpo-35992: Use PySequence_GetItem only if sq_item is not NULL (GH-11857)
Not using `__class_getitem__()` fallback if there is a non-subcriptable metaclass was caused by a certain asymmetry between how `PySequenceMethods` and `PyMappingMethods` are used in `PyObject_GetItem`. This PR removes this asymmetry. No tests failed, so I assume it was not intentional. (cherry picked from commit ac28147e78c45a6217d348ce90ca5281d91f676f) Co-authored-by: Ivan Levkivskyi <levkivskyi@gmail.com>
Diffstat (limited to 'Objects')
-rw-r--r--Objects/abstract.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 2d48a112aa..9416df4321 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -143,6 +143,7 @@ PyObject *
PyObject_GetItem(PyObject *o, PyObject *key)
{
PyMappingMethods *m;
+ PySequenceMethods *ms;
if (o == NULL || key == NULL) {
return null_error();
@@ -155,7 +156,8 @@ PyObject_GetItem(PyObject *o, PyObject *key)
return item;
}
- if (o->ob_type->tp_as_sequence) {
+ ms = o->ob_type->tp_as_sequence;
+ if (ms && ms->sq_item) {
if (PyIndex_Check(key)) {
Py_ssize_t key_value;
key_value = PyNumber_AsSsize_t(key, PyExc_IndexError);
@@ -163,9 +165,10 @@ PyObject_GetItem(PyObject *o, PyObject *key)
return NULL;
return PySequence_GetItem(o, key_value);
}
- else if (o->ob_type->tp_as_sequence->sq_item)
+ else {
return type_error("sequence index must "
"be integer, not '%.200s'", key);
+ }
}
if (PyType_Check(o)) {