Stefan Behnel wrote:
> Lisandro Dalcin wrote:
>> On Tue, May 5, 2009 at 6:28 PM, Stefan Behnel wrote:
>>> I meant
>>>
>>>    cdef MyType(object) [(T,V)]:
>>>
>>> here, although I now noticed that there is already the "private type"
>>> syntax:
>>>
>>> cdef public class _Document [ type LxmlDocumentType, object
>>> LxmlDocument ]:
>>>    ...
>>>
>>> so this won't work straight away either...
>>>
>>
>> But this would work anyway, right?
>
> Not that easily. You could have both [] parts next to each other, or just
> any one of them. So the parser would fail if you decided to call your
> template variable "type", which isn't that a bad name in this context.

How about

cdef class A:
    T, V = cython.template_args(type, type)

?

(The reason for the arguments: In C++ you can have stuff like ints in
template arguments as well, might as well leave the possibility open even
if only passing type is allowed for now).

This even puts T and V in the proper scope for @cython.locals
declarations, e.g. this passes through (and could even be made to do the
checks) in pure Python:

@cython.cdef
class A:
    T, V = template_args(type, type)
    @cython.locals(a=T, b=v)
    def foo(self, a, b): ...

Dag Sverre

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

Reply via email to