Stefan Behnel wrote:
> Hi,
> 
> Dag Sverre Seljebotn wrote:
>> I'm thinking about letting the class author specify default buffer 
>> options. Something like this:
>>
>> cdef extern class Image ...:
>>    __cythonbufferdefaults__ = {'ndim' : 2}
>>    __cythonbuffermandatory__ = {'dtype': unsigned char, indirect=True}
>>    __cythonbufferalways__ = True
> 
> I think default buffer options (mainly a default buffer layout) makes sense in
> general. It's basically saying "when I return a buffer, it will look like 
> this".
> 
> I wonder about the syntax, though. Wouldn't one special name + a couple of
> keyword arguments be enough?

In the discussion with Robert we kind of boiled it down to only defaults 
being needed; at least mandatory has problems and does not really gain 
anything. My preference now would be for __cythonbufferopts__ with a 
tuple or dict giving "defaults", "mandatory" etc.

As for "being enough", in syntax discussions pretty much every syntax 
proposed is possible :-)  My personal taste for new syntax is this:

a) Extends the existing language grammar as little as possible
b) Won't make it harder to get "Python-runnable-Cython-code" in the future,
c) Is somewhat Pythonic (see below).

For usability these may be overriden (as with the buffer access syntax), 
but this is going to be used so seldom that I don't see usability as a 
concern at all -- these are going to be written once or twice per library.

Python has a long tradition of this (like __metaclass__; you and me 
would have thought of all kinds of funky syntax like

class A(B, meta=C):  ...

or perhaps

class A[C](B)

but Guido went with a simple __metaclass__ attribute, meaning a quite 
drastical change in how the class works can be had without any new grammar.


-- 
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to