mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-92114: Improve error message for types with __class_getitem__ = None (GH-92115)
This commit is contained in:
parent
ed711290a0
commit
4d10f703d7
3 changed files with 12 additions and 1 deletions
|
@ -185,11 +185,12 @@ PyObject_GetItem(PyObject *o, PyObject *key)
|
|||
if (_PyObject_LookupAttr(o, &_Py_ID(__class_getitem__), &meth) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (meth) {
|
||||
if (meth && meth != Py_None) {
|
||||
result = PyObject_CallOneArg(meth, key);
|
||||
Py_DECREF(meth);
|
||||
return result;
|
||||
}
|
||||
Py_XDECREF(meth);
|
||||
PyErr_Format(PyExc_TypeError, "type '%.200s' is not subscriptable",
|
||||
((PyTypeObject *)o)->tp_name);
|
||||
return NULL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue