Skip to content

enhancements locals

robertwb edited this page Mar 7, 2008 · 1 revision

The code

def foo(x):
    print y
    y = x

Works in Cython (printing None) but throws an error in Python. This is because all local variables are set to None at the top of a function.

Instead, all locals should be set to 0, with an error being raised on incorrect use. A question is whether or not the C compiler is smart enough to eliminate this check once assignment has been made (especially if it is directly, e.g. via a c attribute). Would the resulting incref be enough?

Some code flow analysis could also be done to clear variables only in the blocks they are used.

Clone this wiki locally