[Python-3000] Adding __format__ to object
Christian Heimes
lists at cheimes.de
Thu Aug 16 20:53:31 CEST 2007
Eric Smith wrote:
> 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()):
>
> 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.
It works for me:
$ LC_ALL=C svn diff Objects/typeobject.c
Index: Objects/typeobject.c
===================================================================
--- Objects/typeobject.c (revision 57099)
+++ Objects/typeobject.c (working copy)
@@ -2938,6 +2938,8 @@
PyDoc_STR("helper for pickle")},
{"__reduce__", object_reduce, METH_VARARGS,
PyDoc_STR("helper for pickle")},
+ {"__format__", object_reduce, METH_VARARGS,
+ PyDoc_STR("helper for pickle")},
{0}
};
$ ./python
Python 3.0x (py3k:57099M, Aug 16 2007, 20:45:17)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> dir(object())
['__class__', '__delattr__', '__doc__', '__eq__', '__format__',
'__ge__', '__getattribute__', '__gt__', '__hash__', '__init__',
'__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__setattr__', '__str__']
>>> object().__format__
<built-in method __format__ of object object at 0xb7d0c468>
>>> object().__format__()
(<function _reconstructor at 0xb7cc71ac>, (<type 'object'>, <type
'object'>, None))
Are you sure that you have changed the correct array?
Christian
More information about the Python-3000
mailing list