[Python-Dev] __reversed__ protocol

Raymond Hettinger python at rcn.com
Tue Nov 18 20:44:13 EST 2003

> Note that the two HasAttrString calls can be quite a bit more
> expensive than the PyRange_Check and PyList_Check calls...

Right!  So we need to keep those:

	if (PyRange_Check(seq) || PyList_Check(seq) ||
	    PyObject_HasAttrString(seq, "__reversed__") && 
	    PyObject_HasAttrString(seq, "__len__"))
		return PyObject_CallMethod(seq, "__reversed__", NULL);


More information about the Python-Dev mailing list