◐ Shell
clean mode source ↗

Message 67947 - Python tracker

Here's the key difference with the way PyObject_Format looks up the
pseudo-slot method:

		PyObject *method = _PyType_Lookup(Py_TYPE(obj),
						  str__format__);

_PyType_Lookup instead of PyObject_GetAttr - so unicode(Exception) would
only look for type.__unicode__ and avoid getting confused by the utterly
irrelevant Exception.__unicode__ method (which is intended only for
printing Exception instances, not for printing the Exception type itself).

You then need the PyInstance_Check/PyObject_GetAttr special case for
retrieving the bound method because _PyType_Lookup won't work on classic
class instances.