[Cython] unbound local variables

Vitja Makarov vitja.makarov at gmail.com
Tue Mar 8 20:12:32 CET 2011


What is the right way to handle cdefed unbounds?

cdef object foo
print foo

cdef int foo
print foo

And how buffers and arrays should be handled? Now I'm skipping
buffers, arrays and structs.


There are some examples in test suite:

------------------------------------------------------------
...
cdef void spam():
    cdef long long L
    cdef unsigned long long U
    cdef object x
    L = x
        ^
------------------------------------------------------------

ass2longlong.pyx:5:9: local variable 'x' referenced before assignment

cdef void spam():
    cdef object x
    del x[17:42]
        ^
------------------------------------------------------------

delslice.pyx:3:9: local variable 'x' referenced before assignment

cdef void tomato():
    cdef Spam spam
    cdef SuperSpam superspam
    spam = superspam
                   ^
------------------------------------------------------------

extcmethcall.pyx:16:20: local variable 'superspam' referenced before assignment

def f(Grail g):
    cdef int i = 0
    cdef Swallow s
    cdef object x
    g = x
        ^
------------------------------------------------------------

extcoerce.pyx:13:9: local variable 'x' referenced before assignment


Should this raise error message or not?

-- 
vitja.


More information about the cython-devel mailing list