From 43246e6dd85ef4647f2c70dfe3a54100aa7227af 2019-01-04 18:44:18 From: Matthias Bussonnier Date: 2019-01-04 18:44:18 Subject: [PATCH] Apply @needs_local_scope to cell magics. While technically this will not be completely needed (at cell magics cannot be in nested scope), it make the API a tiny bit more consistent between line and cell magics. (Bug report I recieved personally that will be submitted later) --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index f98e49c..6a907d5 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2328,8 +2328,13 @@ class InteractiveShell(SingletonConfigurable): magic_arg_s = line else: magic_arg_s = self.var_expand(line, stack_depth) + kwargs = {} + if getattr(fn, "needs_local_scope", False): + kwargs['local_ns'] = sys._getframe(stack_depth).f_locals + with self.builtin_trap: - result = fn(magic_arg_s, cell) + args = (magic_arg_s, cell) + result = fn(*args, **kwargs) return result def find_line_magic(self, magic_name):