diff --git a/IPython/config/loader.py b/IPython/config/loader.py index 743e0b5..c528fa8 100644 --- a/IPython/config/loader.py +++ b/IPython/config/loader.py @@ -478,7 +478,7 @@ class CommandLineConfigLoader(ConfigLoader): # This case happens if the rhs is a string. value = rhs - exec u'self.config.%s = value' % lhs + exec(u'self.config.%s = value' % lhs) def _load_flag(self, cfg): """update self.config from a flag, which can be a dict or Config""" @@ -734,7 +734,7 @@ class ArgParseConfigLoader(CommandLineConfigLoader): def _convert_to_config(self): """self.parsed_data->self.config""" for k, v in vars(self.parsed_data).iteritems(): - exec "self.config.%s = v"%k in locals(), globals() + exec("self.config.%s = v"%k, locals(), globals()) class KVArgParseConfigLoader(ArgParseConfigLoader): """A config loader that loads aliases and flags with argparse, diff --git a/IPython/config/tests/test_loader.py b/IPython/config/tests/test_loader.py index e5fac3e..fe9638a 100644 --- a/IPython/config/tests/test_loader.py +++ b/IPython/config/tests/test_loader.py @@ -256,7 +256,7 @@ class TestConfig(TestCase): def test_builtin(self): c1 = Config() - exec 'foo = True' in c1 + exec('foo = True', c1) self.assertEqual(c1.foo, True) c1.format = "json" diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 095da68..a24b1f3 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2461,7 +2461,7 @@ class InteractiveShell(SingletonConfigurable): def ex(self, cmd): """Execute a normal python statement in user namespace.""" with self.builtin_trap: - exec cmd in self.user_global_ns, self.user_ns + exec(cmd, self.user_global_ns, self.user_ns) def ev(self, expr): """Evaluate python expression expr in user namespace. @@ -2842,7 +2842,7 @@ class InteractiveShell(SingletonConfigurable): try: self.hooks.pre_run_code_hook() #rprint('Running code', repr(code_obj)) # dbg - exec code_obj in self.user_global_ns, self.user_ns + exec(code_obj, self.user_global_ns, self.user_ns) finally: # Reset our crash handler in place sys.excepthook = old_excepthook diff --git a/IPython/core/magics/config.py b/IPython/core/magics/config.py index 39a493f..6a3fb89 100644 --- a/IPython/core/magics/config.py +++ b/IPython/core/magics/config.py @@ -150,7 +150,7 @@ class ConfigMagics(Magics): # leave quotes on args when splitting, because we want # unquoted args to eval in user_ns cfg = Config() - exec "cfg."+line in locals(), self.shell.user_ns + exec("cfg."+line, locals(), self.shell.user_ns) for configurable in configurables: try: diff --git a/IPython/core/magics/execution.py b/IPython/core/magics/execution.py index 692519f..75e16f2 100644 --- a/IPython/core/magics/execution.py +++ b/IPython/core/magics/execution.py @@ -977,7 +977,7 @@ python-profiler package from non-free.""") tc = clock()-t0 ns = {} - exec code in self.shell.user_ns, ns + exec(code, self.shell.user_ns, ns) timer.inner = ns["inner"] if number == 0: @@ -1100,7 +1100,7 @@ python-profiler package from non-free.""") end = clock2() else: st = clock2() - exec code in glob, local_ns + exec(code, glob, local_ns) end = clock2() out = None wall_end = wtime() diff --git a/IPython/core/pylabtools.py b/IPython/core/pylabtools.py index f1bc1ee..c500106 100644 --- a/IPython/core/pylabtools.py +++ b/IPython/core/pylabtools.py @@ -275,12 +275,12 @@ def import_pylab(user_ns, import_all=True): "np = numpy\n" "plt = pyplot\n" ) - exec s in user_ns + exec(s, user_ns) if import_all: s = ("from matplotlib.pylab import *\n" "from numpy import *\n") - exec s in user_ns + exec(s, user_ns) # IPython symbols to add user_ns['figsize'] = figsize diff --git a/IPython/core/tests/test_inputsplitter.py b/IPython/core/tests/test_inputsplitter.py index 526475b..9957d8c 100644 --- a/IPython/core/tests/test_inputsplitter.py +++ b/IPython/core/tests/test_inputsplitter.py @@ -366,7 +366,7 @@ class InteractiveLoopTestCase(unittest.TestCase): """ src = mini_interactive_loop(pseudo_input(lines)) test_ns = {} - exec src in test_ns + exec(src, test_ns) # We can't check that the provided ns is identical to the test_ns, # because Python fills test_ns with extra keys (copyright, etc). But # we can check that the given dict is *contained* in test_ns diff --git a/IPython/extensions/tests/test_autoreload.py b/IPython/extensions/tests/test_autoreload.py index 7e68570..5f71559 100644 --- a/IPython/extensions/tests/test_autoreload.py +++ b/IPython/extensions/tests/test_autoreload.py @@ -45,7 +45,7 @@ class FakeShell(object): self.auto_magics.pre_run_code_hook(self) except TryNext: pass - exec code in self.ns + exec(code, self.ns) def push(self, items): self.ns.update(items) diff --git a/IPython/external/decorator/_decorator.py b/IPython/external/decorator/_decorator.py index e01c5a4..b1f0233 100644 --- a/IPython/external/decorator/_decorator.py +++ b/IPython/external/decorator/_decorator.py @@ -161,7 +161,7 @@ class FunctionMaker(object): try: code = compile(src, '', 'single') # print >> sys.stderr, 'Compiling %s' % src - exec code in evaldict + exec(code, evaldict) except: print('Error in generated code:', file=sys.stderr) print(src, file=sys.stderr) diff --git a/IPython/kernel/zmq/ipkernel.py b/IPython/kernel/zmq/ipkernel.py index 7dc6fcc..0977f3f 100755 --- a/IPython/kernel/zmq/ipkernel.py +++ b/IPython/kernel/zmq/ipkernel.py @@ -596,7 +596,7 @@ class Kernel(Configurable): working.update(ns) code = "%s = %s(*%s,**%s)" % (resultname, fname, argname, kwargname) try: - exec code in shell.user_global_ns, shell.user_ns + exec(code, shell.user_global_ns, shell.user_ns) result = working.get(resultname) finally: for key in ns.iterkeys(): diff --git a/IPython/lib/demo.py b/IPython/lib/demo.py index 0c1fa8e..c0b4787 100644 --- a/IPython/lib/demo.py +++ b/IPython/lib/demo.py @@ -421,7 +421,7 @@ class Demo(object): def run_cell(self,source): """Execute a string with one or more lines of code""" - exec source in self.user_ns + exec(source, self.user_ns) def __call__(self,index=None): """run a block of the demo. diff --git a/IPython/parallel/apps/ipcontrollerapp.py b/IPython/parallel/apps/ipcontrollerapp.py index 275c406..4b16f58 100755 --- a/IPython/parallel/apps/ipcontrollerapp.py +++ b/IPython/parallel/apps/ipcontrollerapp.py @@ -482,7 +482,7 @@ class IPControllerApp(BaseParallelApplication): for s in statements: try: self.log.msg("Executing statement: '%s'" % s) - exec s in globals(), locals() + exec(s, globals(), locals()) except: self.log.msg("Error running statement: %s" % s) diff --git a/IPython/parallel/apps/ipengineapp.py b/IPython/parallel/apps/ipengineapp.py index 4bc5719..5906b9e 100755 --- a/IPython/parallel/apps/ipengineapp.py +++ b/IPython/parallel/apps/ipengineapp.py @@ -355,7 +355,7 @@ class IPEngineApp(BaseParallelApplication): try: self.log.info("Initializing MPI:") self.log.info(mpi_import_statement) - exec mpi_import_statement in globals() + exec(mpi_import_statement, globals()) except: mpi = None else: diff --git a/IPython/parallel/controller/dependency.py b/IPython/parallel/controller/dependency.py index 02ee8fa..8d07d43 100644 --- a/IPython/parallel/controller/dependency.py +++ b/IPython/parallel/controller/dependency.py @@ -80,7 +80,7 @@ def _require(*modules, **mapping): user_ns = globals() for name in modules: try: - exec 'import %s' % name in user_ns + exec('import %s' % name, user_ns) except ImportError: raise UnmetDependency(name) diff --git a/IPython/parallel/util.py b/IPython/parallel/util.py index cf0824a..f36eaa6 100644 --- a/IPython/parallel/util.py +++ b/IPython/parallel/util.py @@ -232,7 +232,7 @@ def _push(**ns): try: for name, value in ns.iteritems(): user_ns[tmp] = value - exec "%s = %s" % (name, tmp) in user_ns + exec("%s = %s" % (name, tmp), user_ns) finally: user_ns.pop(tmp, None) @@ -247,7 +247,7 @@ def _pull(keys): @interactive def _execute(code): """helper method for implementing `client.execute` via `client.apply`""" - exec code in globals() + exec(code, globals()) #-------------------------------------------------------------------------- # extra process management utilities diff --git a/IPython/utils/py3compat.py b/IPython/utils/py3compat.py index 91d5ec7..a2bca3c 100644 --- a/IPython/utils/py3compat.py +++ b/IPython/utils/py3compat.py @@ -98,7 +98,7 @@ if sys.version_info[0] >= 3: def execfile(fname, glob, loc=None): loc = loc if (loc is not None) else glob with open(fname, 'rb') as f: - exec compile(f.read(), fname, 'exec') in glob, loc + exec(compile(f.read(), fname, 'exec'), glob, loc) # Refactor print statements in doctests. _print_statement_re = re.compile(r"\bprint (?P.*)$", re.MULTILINE) @@ -196,7 +196,7 @@ else: filename = unicode_to_str(fname) else: filename = fname - exec compile(scripttext, filename, 'exec') in glob, loc + exec(compile(scripttext, filename, 'exec'), glob, loc) else: def execfile(fname, *where): if isinstance(fname, unicode):