[Python-Dev] Adding __format__ to classic classes

Guido van Rossum guido at python.org
Fri Feb 15 00:12:18 CET 2008


On Thu, Feb 14, 2008 at 2:36 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Eric Smith wrote:
>  > Are you saying I should call _PyType_Lookup first?
>
>  No, I think he's saying that you don't need to call
>  _PyType_Lookup at all, because anything that it could
>  find will also be found by PyObject_GetAttr.
>
>  So just call PyObject_GetAttr and it should Just Work.

In case you missed the final result, that turned out to be wrong too:
format(object, "") dies when you do it that way. We debugged this very
same issue about a year ago, and that's where the _PyType_Lookup call
was found to be the solution. GetAttr should only be used for classic
class instances (PyInstance_Check()).

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list