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

Interactively defined functions can't access user namespace #387

Closed
fperez opened this issue Apr 15, 2011 · 7 comments
Closed

Interactively defined functions can't access user namespace #387

fperez opened this issue Apr 15, 2011 · 7 comments
Assignees
Milestone

Comments

@fperez
Copy link
Member

fperez commented Apr 15, 2011

Simple example:

In [1]: a = 10

In [2]: def f(x):
   ...:     return x+a
   ...: 

In [3]: f(1)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
/etc/cups/ in ()
----> 1 f(1)

/etc/cups/ in f(x)
      1 def f(x):
----> 2     return x+a

NameError: global name 'a' is not defined

This used to work in 0.10.x, I just tested it. I haven't had time to bisect it and have to run now, but this one is absolutely a blocker, unfortunately.

Anyone who can take a stab at it, would be awesome. The first thing to do is to add a failing test for this, I can't believe we didn't have any already...

@minrk
Copy link
Member

minrk commented Apr 15, 2011

Are you working in Thomas' pickle fixing branch?

Because this bug does not exist in master for me (just tested Linux, Windows, and OSX).

@fperez
Copy link
Member Author

fperez commented Apr 15, 2011

On Fri, Apr 15, 2011 at 3:59 PM, minrk
reply@reply.github.com
wrote:

Are you working in Thomas' pickle fixing branch?

Oh, wow, yes! But by accident, I had just finished testing his branch
and left my checkout there, and started doing something else without
realizing that.

Because this bug does not exist in master for me (just tested Linux, Windows, and OSX).

OK, thanks. That's great to hear. @takluyver, that means that a test
of this kind should be added to your pickle branch, so that a) it gets
fixed there b) we have a safety in place for this in the future.

@minrk
Copy link
Member

minrk commented Apr 15, 2011

I just checked, and this is definitely not in master (yet), it's introduced by Thomas' pickle fixing in #384.

@takluyver
Copy link
Member

Ouch, yes. I don't know quite where that's coming from, but I'll look into it.

@ghost ghost assigned takluyver Apr 16, 2011
@takluyver
Copy link
Member

I think that in master, user_ns and user_global_ns point to the same thing when you start the shell. I've broken that link in linking user_ns to user_ns_mod.__dict__. It's going to be tricky to test, though, because in the test environment, user_ns and user_global_ns are already separate objects. In fact, I'm not quite sure why we need two user namespaces - can anyone enlighten me?

@fperez
Copy link
Member Author

fperez commented Apr 16, 2011

Sorry, I'll be offline all day... The reason we have two is to be
able to map to the locals and globals in the exec statement:

exec code in glob, loc

Without both, we can't provide the same semantics, which is important
in cases like embedded ipython shells.

f

@takluyver
Copy link
Member

This is fixed in the branch it affects. Closing for now, reopen if you can replicate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants