This is indeed a problem, however disabling the above line is not a viable solution, as you can see here. If you comment out that last line, you'll get this behavior:
In [9]: cat tclass.py
"""Simple script to instantiate a class for testing %run"""
class foo: pass
def f():
return foo()
x = f()
In [10]: run tclass
In [11]: x
Out[11]: <__main__.foo instance at 0x7fc79a42a638>
In [12]: f()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/fperez/ipython/repo/trunk-dev/IPython/tests/tclass.py in <module>()
----> 1
2
3
4
5
/home/fperez/ipython/repo/trunk-dev/IPython/tests/tclass.py in f()
4
5 def f():
----> 6 return foo()
7
8 x = f()
TypeError: 'NoneType' object is not callable
If that main namespace isn't kept somewhere, it becomes impossible to later use certain things defined in the script (such as instantiating classes).
I still don't have a good solution for this, I'm afraid. Any ideas welcome...
This is indeed a problem, however disabling the above line is not a viable solution, as you can see here. If you comment out that last line, you'll get this behavior:
In [9]: cat tclass.py
"""Simple script to instantiate a class for testing %run"""
class foo: pass
def f():
return foo()
x = f()
In [10]: run tclass
In [11]: x
Out[11]: <__main__.foo instance at 0x7fc79a42a638>
In [12]: f() ------- ------- ------- ------- ------- ------- ------- ------- ------- -----
-------
TypeError Traceback (most recent call last)
/home/fperez/ ipython/ repo/trunk- dev/IPython/ tests/tclass. py in <module>()
----> 1
2
3
4
5
/home/fperez/ ipython/ repo/trunk- dev/IPython/ tests/tclass. py in f()
4
5 def f():
----> 6 return foo()
7
8 x = f()
TypeError: 'NoneType' object is not callable
If that main namespace isn't kept somewhere, it becomes impossible to later use certain things defined in the script (such as instantiating classes).
I still don't have a good solution for this, I'm afraid. Any ideas welcome...