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

Magic local scope #295

Merged
merged 3 commits into from Mar 28, 2011
Merged

Magic local scope #295

merged 3 commits into from Mar 28, 2011

Conversation

takluyver
Copy link
Member

I'm not sure if this is how we want to do this, or if we want to do it at all, but here it is for consideration.

Sage bug 10933 (http://trac.sagemath.org/sage_trac/ticket/10933) highlighted that we couldn't use the %time magic command inside a function. This captures the stack frame which called magic_time, and uses its local namespace to evaluate or execute the code passed to %time. It could also be used by other magic functions, although so far I've only added it to magic_time.

@@ -1734,6 +1735,10 @@ class InteractiveShell(Configurable, Magic):
valid Python code you can type at the interpreter, including loops and
compound statements.
"""
# Save the scope of the call so magic functions like %time can
# evaluate expressions in it.
self._magic_locals = inspect.stack()[1][0].f_locals
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at utils.frame, and add a decorator so we're only doing this if the magic command needs it.

@fperez
Copy link
Member

fperez commented Mar 24, 2011

Reviewed during sage days 29 sprint, ready for merge after minor fixes discussed there. Thanks!

@takluyver
Copy link
Member Author

OK, I've revised it as we agreed. I've also rebased on master, so that I could test it easily.

@fperez fperez merged commit 9a34540 into ipython:master Mar 28, 2011
@fperez
Copy link
Member

fperez commented Mar 28, 2011

I've merged and pushed it with --no-ff to preserve the history together, since it was 3 commits. My rule of thumb is to force no-ff even if the merge could have been fast-forward if the branch has 3 or more commits, since at that point it becomes useful to see them together. For just one or two, I let the fast-forward go through.

Thanks for the good work!

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

Successfully merging this pull request may close these issues.

None yet

2 participants