Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use eval to uncan References #1458

Merged
merged 1 commit into from
Mar 1, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions IPython/parallel/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,4 +490,18 @@ def test_apply_reference(self):
result = v.apply_sync(rf, 5)
expected = [ 5*id for id in self.client.ids ]
self.assertEquals(result, expected)

def test_eval_reference(self):
v = self.client[self.client.ids[0]]
v['g'] = range(5)
rg = pmod.Reference('g[0]')
echo = lambda x:x
self.assertEquals(v.apply_sync(echo, rg), 0)

def test_reference_nameerror(self):
v = self.client[self.client.ids[0]]
r = pmod.Reference('elvis_has_left')
echo = lambda x:x
self.assertRaisesRemote(NameError, v.apply_sync, echo, r)


6 changes: 2 additions & 4 deletions IPython/utils/pickleutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ def __repr__(self):
def getObject(self, g=None):
if g is None:
g = globals()
try:
return g[self.name]
except KeyError:
raise NameError("name %r is not defined"%self.name)

return eval(self.name, g)


class CannedFunction(CannedObject):
Expand Down