[IPython-dev] refactoring magics

Thomas Kluyver takowl at gmail.com
Wed Sep 11 14:49:08 EDT 2013


On 11 September 2013 11:16, Matthias BUSSONNIER <
bussonniermatthias at gmail.com> wrote:

> What about a decorator ? It does not give author much choice.


I think the best way is to use the @needs_local_scope decorator, and change
the api of var_expand a bit. The reason that var_expand needs a stack depth
is so that it can find the local scope, if the magic is called within a
function (which can't happen for a cell magic, in any case). We can easily
get a reference to the global user namespace.

With the @needs_local_scope decorator, the magic function gets a keyword
argument local_ns with the namespace of the function from which it was
called. It could then pass that to var_expand() instead of a stack depth.
We're already using that decorator, e.g. for %time and %Rpush, so this
seems like the simplest approach.

Have we thought about which magic functions should continue to expand
variables?

Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20130911/7ea7dbce/attachment.html>


More information about the IPython-dev mailing list