numba/numba — pull request #305 by bfredl (2013-07-29 19:00:25+00:00)
Title: Fix glitches ocurring in interactive use

When reloading new versions of the same module into the same session (i e an interactive ipython session), numba sometimes gets the wrong version of the source from inspect.getsource().

from numba import jit
fn = "/tmp/numbatest.py"
with open(fn,'w') as f:
f.write("""
@jit('i8()')
def test():
return 0
""")
execfile(fn)

with open(fn,'w') as f:
f.write("""
@jit('i8()')
def test():
return 1
""")

execfile(fn)
print test(), '==', test.py_func() # gives 0 == 1

the old version is still kept in the cache, easily fixed by checking the cache at compilation (first commit)

from numba import autojit
fn = "/tmp/numbatest2.py"
with open(fn,'w') as f:
f.write("""
@autojit
def test2():
return 0
""")
execfile(fn)

with open(fn,'w') as f:
f.write("""
@autojit
def test2():
return 1
""")

# note that we don't reexec the file

print test2(), '==', test2.py_func() # gives 1 == 0

In this case autojit 'sees' the new version of the source even if it hasn't been reloaded. This could be fixed by fetching the ast directly at declaration time rather that at first compilation (2nd commit)