Re: [Python-Dev] Calling a builtin from C code; PEP 3101 format() builtin

2008-02-15 Thread Eric Smith
Eric Smith wrote:
> Greg Ewing wrote:
>> Eric Smith wrote:
>>
>>> 1: exposing builtin_format(), probably giving it another name 
>>> (PyObject_Format?) and moving it somewhere other than bltinmodule.c.
>> PyObject_Format sounds more like an API for invoking the
>> __format__ lookup mechanism. Maybe something like
>> PyObject_DefaultFormat would be better.
> 
> I see it like:
> PyObject_Str(o) gives you str(o),
> PyObject_Unicode(o) gives you unicode(o)
> so
> PyObject_Format(o, spec) give you format(o, spec).
> 
> All 3 of them do things with __special__ methods.

Having heard no objections, I'm going to call this PyObject_Format and 
put it in abstract.c.

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


Re: [Python-Dev] Calling a builtin from C code; PEP 3101 format() builtin

2008-02-15 Thread Eric Smith
Greg Ewing wrote:
> Eric Smith wrote:
> 
>> 1: exposing builtin_format(), probably giving it another name 
>> (PyObject_Format?) and moving it somewhere other than bltinmodule.c.
> 
> PyObject_Format sounds more like an API for invoking the
> __format__ lookup mechanism. Maybe something like
> PyObject_DefaultFormat would be better.

I see it like:
PyObject_Str(o) gives you str(o),
PyObject_Unicode(o) gives you unicode(o)
so
PyObject_Format(o, spec) give you format(o, spec).

All 3 of them do things with __special__ methods.

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


Re: [Python-Dev] Calling a builtin from C code; PEP 3101 format() builtin

2008-02-14 Thread Eric Smith
Greg Ewing wrote:
> Eric Smith wrote:
> 
>> 1: exposing builtin_format(), probably giving it another name 
>> (PyObject_Format?) and moving it somewhere other than bltinmodule.c.
> 
> PyObject_Format sounds more like an API for invoking the
> __format__ lookup mechanism. Maybe something like
> PyObject_DefaultFormat would be better.

I see it like:
PyObject_Str(o) gives you str(o),
PyObject_Unicode(o) gives you unicode(o)
so
PyObject_Format(o, spec) give you format(o, spec).

All 3 of them do things with __special__ methods.

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


Re: [Python-Dev] Calling a builtin from C code; PEP 3101 format() builtin

2008-02-14 Thread Greg Ewing
Eric Smith wrote:

> 1: exposing builtin_format(), probably giving it another name 
> (PyObject_Format?) and moving it somewhere other than bltinmodule.c.

PyObject_Format sounds more like an API for invoking the
__format__ lookup mechanism. Maybe something like
PyObject_DefaultFormat would be better.

--
Greg
___
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


Re: [Python-Dev] Calling a builtin from C code; PEP 3101 format() builtin

2008-02-14 Thread Nick Coghlan
Eric Smith wrote:
> I see 2 approaches:
> 
> 1: exposing builtin_format(), probably giving it another name 
> (PyObject_Format?) and moving it somewhere other than bltinmodule.c.
> 
> 2: Instead of calling the C code directly, lookup "format" in Python's
> builtins, and call it.  This, I think, would allow you to override the
> global format() function if you wanted to modify the behavior (although
> I can't think of any use case for wanting to do that).
> 
> I don't see where either behavior is specified in the PEP.

abstract.h/abstract.c is where most of the PyObject_* functions live, so 
that would be a likely location if we do go with option 1.

Given that the formatting PEP goes to great lengths to describe how to 
make your own custom formatters, I'd be inclined to favour option 1 myself.

Cheers,
Nick.

-- 
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
 http://www.boredomandlaziness.org
___
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


Re: [Python-Dev] Calling a builtin from C code; PEP 3101 format() builtin

2008-02-14 Thread Georg Brandl
Eric Smith schrieb:
> While implementing "".format(), I need to call the builtin format()
> function, which I've already implemented (in
> bltinmodule.c:builtin_format()).  In the py3k branch, I just hardcoded
> the same functionality into "".format(), which seems like the wrong 
> thing to do, given how complex the code is.
> 
> I see 2 approaches:
> 
> 1: exposing builtin_format(), probably giving it another name 
> (PyObject_Format?) and moving it somewhere other than bltinmodule.c.
> 
> 2: Instead of calling the C code directly, lookup "format" in Python's
> builtins, and call it.  This, I think, would allow you to override the
> global format() function if you wanted to modify the behavior (although
> I can't think of any use case for wanting to do that).
> 
> I don't see where either behavior is specified in the PEP.
> 
> If option 2 is preferred, could someone give me a pointer to how to find 
> a builtin function from C code?

I don't know which option Guido prefers, but for looking up a function
from the builtins, look at Python/import.c:PyImport_Import which does
this with __import__.

Georg


-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.

___
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


[Python-Dev] Calling a builtin from C code; PEP 3101 format() builtin

2008-02-14 Thread Eric Smith
While implementing "".format(), I need to call the builtin format()
function, which I've already implemented (in
bltinmodule.c:builtin_format()).  In the py3k branch, I just hardcoded
the same functionality into "".format(), which seems like the wrong 
thing to do, given how complex the code is.

I see 2 approaches:

1: exposing builtin_format(), probably giving it another name 
(PyObject_Format?) and moving it somewhere other than bltinmodule.c.

2: Instead of calling the C code directly, lookup "format" in Python's
builtins, and call it.  This, I think, would allow you to override the
global format() function if you wanted to modify the behavior (although
I can't think of any use case for wanting to do that).

I don't see where either behavior is specified in the PEP.

If option 2 is preferred, could someone give me a pointer to how to find 
a builtin function from C code?

Thanks.



___
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