[Python-3000] Adding __format__ to object

Eric Smith eric+python-dev at trueblade.com
Thu Aug 16 17:09:56 CEST 2007


Christian Heimes wrote:
> Eric Smith wrote:
>> Any pointers are appreciated.  Something as simple as "look at foo.c" or 
>> "grep for __baz__" would be good enough.
> 
> look at Objects/typeobject.c and grep for PyMethodDef object_methods[]

I should have mentioned that's among the things I've already tried.

But that appears to add methods to 'type', not to an instance of 
'object'.  If you do dir(object()):

$ ./python
Python 3.0x (py3k:57077M, Aug 16 2007, 10:10:04)
[GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> dir(object())
['__class__', '__delattr__', '__doc__', '__eq__', '__ge__', 
'__getattribute__', '__gt__', '__hash__', '__init__', '__le__', 
'__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', 
'__repr__', '__setattr__', '__str__']

You don't see the methods in typeobject.c (__mro__, etc).

This is pretty much the last hurdle in finishing my implementation of 
PEP 3101.  The rest of it is either done, or just involves refactoring 
existing code.

Eric.


More information about the Python-3000 mailing list