Please sign in to comment.
Merge pull request #648 from takluyver/usermod
Clean up handling of global namespaces with the proper semantics. A global namespace should always be tied to a module: pickle accesses classes via the module in which they're defined. So I've changed the arguments for instantiating an InteractiveShell to include `user_module` in place of `user_global_ns`. The global namespace simply becomes a reference to `user_module.__dict__`. For instantiating InteractiveShell, there are four possibilities: * Neither `user_ns` nor `user_module` is given. A new (real) module is created named `__main__`, and its `__dict__` becomes the global and local namespace. This is what happens when starting IPython normally. * Only `user_module` is given. Its `__dict__` becomes the global and local namespace. * Both `user_ns` and `user_module` are given. `user_module.__dict__` is the global namespace, and `user_ns` is the local namespace. Note that we can't interactively define closures over variables in the local namespace (this seems to be a limitation of Python). * Only `user_ns` is given. It is treated as the global and local namespace, and a `DummyMod` object is created to refer to it. This is intended as a convenience, especially for the test suite. The recommended way to pass in a single global namespace is as a reference to the module. `embed()` digs out the locals and the module from the frame in which it's called. Closes gh-29, closes gh-693.
- Loading branch information...
Showing with 194 additions and 172 deletions.
- +4 −4 IPython/core/displayhook.py
- +2 −1 IPython/core/history.py
- +89 −120 IPython/core/interactiveshell.py
- +1 −2 IPython/core/magic.py
- +1 −1 IPython/core/prefilter.py
- +33 −0 IPython/core/tests/test_interactiveshell.py
- +3 −13 IPython/core/tests/test_iplib.py
- +12 −0 IPython/core/tests/test_run.py
- +32 −26 IPython/frontend/terminal/embed.py
- +2 −2 IPython/frontend/terminal/interactiveshell.py
- +1 −3 IPython/testing/globalipapp.py
- +4 −0 IPython/testing/plugin/ipdoctest.py
- +10 −0 docs/source/whatsnew/development.txt