[Cython] A brand new syntax idea I actually like!
Robert Bradshaw
robertwb at math.washington.edu
Wed Aug 6 18:32:43 CEST 2008
On Aug 6, 2008, at 8:18 AM, Dag Sverre Seljebotn wrote:
> Realistically, the old [] syntax is here for the next Cython
> release so
> I might move on to fix that bug...
>
> But here's an idea for a syntax I actually like (let's hear about
> you)...:
>
> Somehow specify that the variable in question has TWO types. I.e., it
> supports the ndarray interface, as well as the buffer interface.
>
> So, for buffers this would becom
>
> cdef ndarray,buffer(int, 2) buf = ... # ndarray supporting buffer
>
> cdef buffer(int, 2) buf = ... # plain object supporting buffer
> cdef object,buffer(int, 2) buf = ... # same as above
>
> If it is possible with objects that inherit from two extension types
> (didn't try it) this could even be used like this:
>
> cdef MyType1,MyType2 obj = ...
>
> This would make the syntax "explain" what happens today anyway, with
> "cdef MyType1 obj" being shorthand for "cdef object,MyType1 obj". I.e.
> "first try to resolve compile-time towards MyType1, and then towards
> object".
>
> *running away and ducking* :-)
-1. 99% of the time such declarations would be either impossible or
implied (e.g. with inheritance), and the Python way to do things like
this in multiple inheritance (which we can't do from Cython without
an additional virtual lookup penalty). Also, this syntax is much more
verbose, and hard to parse (think about argument declarations, or
"cdef a, b" declares two variables, but "cdef a, b c" declares one?
- Robert
More information about the Cython-dev
mailing list