Return 1 if the object provides the mapping protocol or supports slicing, and 0 otherwise.
I think or is wrong.Because in cpython/Objects/abstract.c.We have:
int
PyMapping_Check(PyObject *o)
{
return o && Py_TYPE(o)->tp_as_mapping &&
Py_TYPE(o)->tp_as_mapping->mp_subscript;
}
I think “Return 1 if the object provides the mapping protocol or supports slicing, and 0 otherwise.” should be
“Return 1 if the object provides the mapping protocol and supports slicing, and 0 otherwise.”
Both the code and the docs are correct. There is a bit of an optical illusion with the “and/or” and you may just need to puzzle it out. What I think you’re missing is that the mp_subscript slot can arise either from slicing OR from mapping. Also, the presence tp_as_mapping doesn’t mean “is a mapping”; instead, it means “uses one of the mapping slots”.