diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 9c59da8..de4c994 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2023,21 +2023,21 @@ class InteractiveShell(SingletonConfigurable): if next_input: self.set_next_input(next_input) - magic_name, _, magic_args = arg_s.partition(' ') + magic_name, _, magic_arg_s = arg_s.partition(' ') magic_name = magic_name.lstrip(prefilter.ESC_MAGIC) fn = self.find_magic(magic_name) if fn is None: error("Magic function `%s` not found." % magic_name) else: - magic_args = self.var_expand(magic_args, 1) + magic_arg_s = self.var_expand(magic_arg_s, 1) + # Put magic args in a list so we can call with f(*a) syntax + args = [magic_arg_s] # Grab local namespace if we need it: if getattr(fn, "needs_local_scope", False): - self._magic_locals = sys._getframe(1).f_locals + args.append(sys._getframe(1).f_locals) with self.builtin_trap: - result = fn(magic_args) - # Ensure we're not keeping object references around: - self._magic_locals = {} + result = fn(*args) return result def define_magic(self, magic_name, func): diff --git a/IPython/core/magic.py b/IPython/core/magic.py index d15047e..5269e7a 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -2017,7 +2017,7 @@ Currently the magic system has the following functions:\n""" @skip_doctest @needs_local_scope - def magic_time(self,parameter_s = ''): + def magic_time(self,parameter_s, user_locals): """Time execution of a Python statement or expression. The CPU and wall clock times are printed, and the value of the @@ -2084,19 +2084,17 @@ Currently the magic system has the following functions:\n""" tc = clock()-t0 # skew measurement as little as possible glob = self.shell.user_ns - locs = self._magic_locals - clk = clock2 wtime = time.time # time execution wall_st = wtime() if mode=='eval': - st = clk() - out = eval(code, glob, locs) - end = clk() + st = clock2() + out = eval(code, glob, user_locals) + end = clock2() else: - st = clk() - exec code in glob, locs - end = clk() + st = clock2() + exec code in glob, user_locals + end = clock2() out = None wall_end = wtime() # Compute actual times and report