[Cython] template types
Stefan Behnel
stefan_ml at behnel.de
Tue May 5 23:11:10 CEST 2009
Dag Sverre Seljebotn wrote:
> OTOH, this brings up another interesting question: What happens with
> exporting templates to Python-land?
>
> If there was indeed something very like typedef, but which also made the
> templated type available Python-side...
>
> I guess
>
> IntVector = Vector<int>
>
> would currently achieve that without any further magic though.
Sure.
> With [] or () or somesuch one could export some wrapper type for
> "Vector" and look up the Vector[cython.int] type from Python-space,
> however one must know compile-time which templates to instantiate for
> Python access anyway. The template types to always instantiate and
> export to Python could perhaps be embedded in the template declaration
> syntax.
Why? If you want to provide a type to Python space, you can just
instantiate it somewhere in your program, e.g. by adding it to a name->type
mapping. No magic whatsoever involved.
> (I'd say that's a valid usecase eventually, but of course not something
> to support at first. But it /does/ impact the chosen syntax quite
> heavily as <> is ruled straight out.)
The syntax would be Cython-only, no need to move it into Python.
Stefan
More information about the Cython-dev
mailing list