[Cython] Prototype for parametrized types
Robert Bradshaw
robertwb at math.washington.edu
Mon Mar 10 21:29:44 CET 2008
On Mar 10, 2008, at 11:44 AM, Stefan Behnel wrote:
> Hi,
>
> Robert Bradshaw wrote:
>> On Mar 10, 2008, at 12:10 AM, Stefan Behnel wrote:
>>> Dag Sverre Seljebotn wrote:
>>>> We all agree that decorating variables in real Python is a real
>>>> problem,
>>>> but this proposal doesn't change anything for better or worse
>>>> considering that. What this proposal says is that, given a
>>>> hyopthetical
>>>> CEP102 that proposes the following syntax for declaring types of
>>>> in-function variables:
>>>>
>>>> i = typed(int)
>>>>
>>>> then a consequence of my proposal is that it is legal to also say
>>>>
>>>> v = typed(cpp.vector(int))
>>>
>>> I hope it won't be that syntax, as this is what an assignment from a
>>> function
>>> call looks like, this is not a declaration. Declarative syntax
>>> should
>>> not be
>>> easily confused with syntax that results in real code doing
>>> something.
>>
>> My suggestion would be something of the form
>>
>> i = cython.types.int
>> v = cython.types.cpp.vector(int)
>>
>> This would also have the right feel to it if type inference is done
>> (though in the this case, assignment to i of a non-int would not
>> change
>> the type of i).
>
> I'm still not convinced that assignment is a good way of dealing
> with type
> declarations.
>
> Wouldn't something like this work as well:
>
> def dostuff(a : int, b : str):
> type(c, char*)
> c = b
>
> or
>
> def dostuff(a : int, b : str):
> assert type(c, char*)
> c = b
>
> or maybe
>
> def dostuff(a : int, b : str):
> cython.assert_type(c, char*)
> c = b
>
> This /would/ be valid Python syntax as long as you use only plain
> Python
> types. And it's definitely more intuitive than an assignment.
Perhaps. This would give you a runtime error in python though.
> Alternatively, I could imagine typing values at the first
> assignment. So, what
> about this:
>
> def dostuff(a : int, b : str):
> c = cython.assigntype(char*, b)
>
> Again, plain Python if you stick to Python types. But this time, it
> really
> *is* an assignment.
Looking at stuff like this makes me realize how nice the cdef keyword
really is...
- Robert
More information about the Cython-dev
mailing list