[Cython] CF based type inference

Dag Sverre Seljebotn d.s.seljebotn at astro.uio.no
Wed May 9 17:58:07 CEST 2012

On 05/09/2012 05:13 PM, Stefan Behnel wrote:
> Dag Sverre Seljebotn, 08.05.2012 18:52:
>> Vitja Makarov wrote:
>>> def partial_validity():
>>>    """
>>>    >>>  partial_validity()
>>>    ('str object', 'double', 'str object')
>>>    """
>>>    a_1 = 1.0
>>>    b = a_1 + 2   # definitely double
>>>    a_2 = 'test'
>>>    c = a_2 + 'toast'  # definitely str
>>>    return typeof(a_2), typeof(b), typeof(c)
>>> And this should work better because it allows to infer a_1 as a double
>>> and a_2 as a string.
>> +1 (as also Mark has hinted several times). I also happen to like that
>> typeof returns str rather than object... I don't think type inferred code
>> has to restrict itself to what you could dousing *only* declarations.
>> To go out on a hyperbole: Reinventing compiler theory to make things
>> fit better with our current tree and the Pyrex legacy isn't sustainable
>> forever, at some point we should do things the standard way and
>> refactor some code if necesarry.
> That's how these things work, though. It's basically register allocation
> and variable renaming mapped to a code translator (rather than a compiler
> that emits assembly or byte code).

Yes, to be crystal clear, I was actually hinting at your original 
proposal here, and applauding Vitja's counter-proposal as a more 
standard way of doing things.

But I regretted posting at all afterwards, I do so little coding on 
Cython these days that I shouldn't interfer at this level. I'll try to 
leave such rants to Mark in the future :-)


More information about the cython-devel mailing list