[Cython] Type inference question

Vitja Makarov vitja.makarov at gmail.com
Sat Nov 26 17:10:48 CET 2011


Hi!

I'm now trying to make inlined generator expressions work again. And I
found strange thing:

inlined_generator_expression.pyx:

def range_sum(int N):
    """
    >>> sum(range(10))
    45
    >>> range_sum(10)
    45
    """
    result = sum(i for i in range(N))
    return result

'i' is expected to be integer, but it isn't

So I tried simple example and 'i' is inferred as object:

def bar(int N):
    cdef int result = 0
    for i in range(N):
        result += i
    return result

So, I'm wondering should it be inferred as int or not?

-- 
vitja.


More information about the cython-devel mailing list