Guido van Rossum wrote: > On Feb 13, 2008 5:28 AM, Eric Smith <[EMAIL PROTECTED]> wrote: >> When backporting PEP 3101, do we want to add __format__ to classic >> classes? If so, could someone give me a pointer on how to implement >> this? I don't see where to hook it up. > > You just have to get the '__format__' attribute and call it if it > exists. Isn't that how you do it for new-style classes too? >
I'm thinking that I need to add a __format__ to the "most base" old style class, similar to how I added it for object itself (in object_methods[]). As I currently have it in 2.6, I can call __format__ on a new style class, but not a classic class: $ ./python.exe Python 2.6a0 (trunk:60757M, Feb 13 2008, 09:14:18) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class newstyle(object): pass ... >>> class oldstyle: pass ... >>> newstyle().__format__('') '<__main__.newstyle object at 0x3d4d90>' >>> oldstyle().__format__('') Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: oldstyle instance has no attribute '__format__' >>> So my question is, to what do I need to add __format__ so that classic classes will have a default implementation? My knowledge of how classic classes are implemented is weak, so I don't know where to add this. Eric. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com