Issue
Embedded IPython shells can lose track of local variables.
Test Case
Minimal test case:
class Foo(object):
""" Container-like object """
def __setattr__(self, obj, val):
self.__dict__[obj] = val
def __getattr__(self, obj, val):
return self.__dict__[obj]
f = Foo()
f.indices = set([1,2,3,4,5])
f.values = {}
for x in f.indices:
f.values[x] = x
def bar(foo):
import IPython
IPython.Shell.IPShellEmbed()()
return sum(foo.values[x] for x in foo.indices)
print bar(f)
To see the error, first run the code in Python (or IPython) and exit from the spawned shell; the final print statement correctly displays '15'. Run the code again, but this time type sum(foo.values[x] for x in foo.indices) in the spawned shell, and we receive the error
" NameError: global name 'foo' is not defined".
Reactions are currently unavailable
Issue
Embedded IPython shells can lose track of local variables.
Test Case
Minimal test case:
class Foo(object): """ Container-like object """ def __setattr__(self, obj, val): self.__dict__[obj] = val def __getattr__(self, obj, val): return self.__dict__[obj] f = Foo() f.indices = set([1,2,3,4,5]) f.values = {} for x in f.indices: f.values[x] = x def bar(foo): import IPython IPython.Shell.IPShellEmbed()() return sum(foo.values[x] for x in foo.indices) print bar(f)To see the error, first run the code in Python (or IPython) and exit from the spawned shell; the final print statement correctly displays '15'. Run the code again, but this time type sum(foo.values[x] for x in foo.indices) in the spawned shell, and we receive the error