Re: [Python-Dev] Adding __format__ to classic classes

2008-02-14 Thread Guido van Rossum
On Thu, Feb 14, 2008 at 2:36 PM, Greg Ewing <[EMAIL PROTECTED]> 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

Re: [Python-Dev] Adding __format__ to classic classes

2008-02-14 Thread Greg Ewing
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. -- Greg ___

Re: [Python-Dev] Adding __format__ to classic classes

2008-02-14 Thread Eric Smith
Guido van Rossum wrote: > Try this: > > if (PyInstance_Check(obj)) { > bound_method = PyObject_GetAttr(obj, str__format__); > if (!bound_method) > return NULL; > > Py_DECREF(bound_method); > return > } > else { > do it the py3k way; > } Yes! I had converged on something similar.

Re: [Python-Dev] Adding __format__ to classic classes

2008-02-13 Thread Guido van Rossum
Try this: if (PyInstance_Check(obj)) { bound_method = PyObject_GetAttr(obj, str__format__); if (!bound_method) return NULL; Py_DECREF(bound_method); return } else { do it the py3k way; } On Feb 13, 2008 5:31 PM, Eric Smith <[EMAIL PROTECTED]> wrote: > [slight mailer problem, thi

Re: [Python-Dev] Adding __format__ to classic classes

2008-02-13 Thread Jeffrey Yasskin
Oops, sorry for the spam. I didn't see that there were already answers in the rest of the thread. :-( On Feb 13, 2008 9:25 PM, Jeffrey Yasskin <[EMAIL PROTECTED]> wrote: > On Feb 13, 2008 1:42 PM, Eric Smith <[EMAIL PROTECTED]> wrote: > > Guido van Rossum wrote: > > >> Much to my surprise, this al

Re: [Python-Dev] Adding __format__ to classic classes

2008-02-13 Thread Jeffrey Yasskin
On Feb 13, 2008 1:42 PM, Eric Smith <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > >> Much to my surprise, this already works: > >> > >> >>> format(oldstyle(), '+^50s') > >> '+<__main__.oldstyle instance at 0x3d91f8>+' > >> >>> > >> > >> So I guess it's a moot point. I'm using th

Re: [Python-Dev] Adding __format__ to classic classes

2008-02-13 Thread Eric Smith
[slight mailer problem, this might show up as a dupe. sorry] Guido van Rossum wrote: > On Feb 13, 2008 2:57 PM, Eric Smith <[EMAIL PROTECTED]> wrote: >> Guido van Rossum wrote: >>> On Feb 13, 2008 2:20 PM, Eric Smith <[EMAIL PROTECTED]> wrote: Nick Coghlan wrote: > However, the source cod

Re: [Python-Dev] Adding __format__ to classic classes

2008-02-13 Thread Guido van Rossum
On Feb 13, 2008 2:57 PM, Eric Smith <[EMAIL PROTECTED]> wrote: > > Guido van Rossum wrote: > > On Feb 13, 2008 2:20 PM, Eric Smith <[EMAIL PROTECTED]> wrote: > >> Nick Coghlan wrote: > >>> Eric Smith wrote: > I hate to be dense, but could you point me to some code that does > something si

Re: [Python-Dev] Adding __format__ to classic classes

2008-02-13 Thread Eric Smith
Guido van Rossum wrote: > On Feb 13, 2008 2:20 PM, Eric Smith <[EMAIL PROTECTED]> wrote: >> Nick Coghlan wrote: >>> Eric Smith wrote: I hate to be dense, but could you point me to some code that does something similar but looks up the method by name? >>> I was going to suggest __enter__/_

Re: [Python-Dev] Adding __format__ to classic classes

2008-02-13 Thread Guido van Rossum
On Feb 13, 2008 2:20 PM, Eric Smith <[EMAIL PROTECTED]> wrote: > Nick Coghlan wrote: > > Eric Smith wrote: > >> I hate to be dense, but could you point me to some code that does > >> something similar but looks up the method by name? > > > > I was going to suggest __enter__/__exit__, but that code

Re: [Python-Dev] Adding __format__ to classic classes

2008-02-13 Thread Eric Smith
Nick Coghlan wrote: > Eric Smith wrote: >> I hate to be dense, but could you point me to some code that does >> something similar but looks up the method by name? > > I was going to suggest __enter__/__exit__, but that code relies mainly > on existing opcodes and just does an attribute lookup ra

Re: [Python-Dev] Adding __format__ to classic classes

2008-02-13 Thread Nick Coghlan
Eric Smith wrote: > I hate to be dense, but could you point me to some code that does > something similar but looks up the method by name? I was going to suggest __enter__/__exit__, but that code relies mainly on existing opcodes and just does an attribute lookup rather than explicitly bypassin

Re: [Python-Dev] Adding __format__ to classic classes

2008-02-13 Thread Eric Smith
Guido van Rossum wrote: >> Much to my surprise, this already works: >> >> >>> format(oldstyle(), '+^50s') >> '+<__main__.oldstyle instance at 0x3d91f8>+' >> >>> >> >> So I guess it's a moot point. I'm using the same code as I use in 3.0, >> where I call: >>meth = _PyType_Lookup(Py_TY

Re: [Python-Dev] Adding __format__ to classic classes

2008-02-13 Thread Guido van Rossum
On Feb 13, 2008 12:07 PM, Eric Smith <[EMAIL PROTECTED]> wrote: > > Guido van Rossum wrote: > > On Feb 13, 2008 9:48 AM, Eric Smith <[EMAIL PROTECTED]> wrote: > >> Guido van Rossum wrote: > >>> On Feb 13, 2008 5:28 AM, Eric Smith <[EMAIL PROTECTED]> wrote: > When backporting PEP 3101, do we wa

Re: [Python-Dev] Adding __format__ to classic classes

2008-02-13 Thread Eric Smith
Guido van Rossum wrote: > On Feb 13, 2008 9:48 AM, Eric Smith <[EMAIL PROTECTED]> wrote: >> 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

Re: [Python-Dev] Adding __format__ to classic classes

2008-02-13 Thread Guido van Rossum
On Feb 13, 2008 9:48 AM, Eric Smith <[EMAIL PROTECTED]> wrote: > 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 impleme

Re: [Python-Dev] Adding __format__ to classic classes

2008-02-13 Thread Eric Smith
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

Re: [Python-Dev] Adding __format__ to classic classes

2008-02-13 Thread Guido van Rossum
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 c

[Python-Dev] Adding __format__ to classic classes

2008-02-13 Thread Eric Smith
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. Thanks. Eric. ___ Python-Dev mailing list Python-Dev@python.org http://mail.