diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index dfec7ba..5875e4b 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -903,10 +903,6 @@ class InteractiveShell(SingletonConfigurable, Magic): # doesn't need to be separately tracked in the ns_table. self.user_ns_hidden = set() - # A namespace to keep track of internal data structures to prevent - # them from cluttering user-visible stuff. Will be updated later - self.internal_ns = {} - # Now that FakeModule produces a real module, we've run into a nasty # problem: after script execution (via %run), the module where the user # code ran is deleted. Now that this object is a true module (needed @@ -940,17 +936,8 @@ class InteractiveShell(SingletonConfigurable, Magic): # introspection facilities can search easily. self.ns_table = {'user_global':self.user_module.__dict__, 'user_local':user_ns, - 'internal':self.internal_ns, 'builtin':builtin_mod.__dict__ } - - # Similarly, track all namespaces where references can be held and that - # we can safely clear (so it can NOT include builtin). This one can be - # a simple list. Note that the main execution namespaces, user_ns and - # user_global_ns, can NOT be listed here, as clearing them blindly - # causes errors in object __del__ methods. Instead, the reset() method - # clears them manually and carefully. - self.ns_refs_table = [ self.internal_ns, self._main_ns_cache ] @property def user_global_ns(self): @@ -1085,10 +1072,6 @@ class InteractiveShell(SingletonConfigurable, Magic): if self.displayhook.do_full_cache: self.displayhook.flush() - # Restore the user namespaces to minimal usability - for ns in self.ns_refs_table: - ns.clear() - # The main execution namespaces must be cleared very carefully, # skipping the deletion of the builtin-related keys, because doing so # would cause errors in many object's __del__ methods. @@ -1128,10 +1111,10 @@ class InteractiveShell(SingletonConfigurable, Magic): """ if varname in ('__builtin__', '__builtins__'): raise ValueError("Refusing to delete %s" % varname) - ns_refs = self.ns_refs_table + [self.user_ns, - self.user_global_ns, self._user_main_module.__dict__] +\ - self._main_ns_cache.values() + ns_refs = [self.user_ns, self.user_global_ns, + self._user_main_module.__dict__] + self._main_ns_cache.values() + if by_name: # Delete by name for ns in ns_refs: try: @@ -1172,7 +1155,7 @@ class InteractiveShell(SingletonConfigurable, Magic): raise TypeError('regex must be a string or compiled pattern') # Search for keys in each namespace that match the given regex # If a match is found, delete the key/value pair. - for ns in self.ns_refs_table: + for ns in [self.user_ns, self.user_global_ns]: for var in ns: if m.search(var): del ns[var] @@ -1266,7 +1249,7 @@ class InteractiveShell(SingletonConfigurable, Magic): # Put them in a list. The order is important so that we # find things in the same order that Python finds them. namespaces = [ ('Interactive', self.user_ns), - ('IPython internal', self.internal_ns), + ('Interactive (global)', self.user_global_ns), ('Python builtin', builtin_mod.__dict__), ('Alias', self.alias_manager.alias_table), ] diff --git a/IPython/core/magic.py b/IPython/core/magic.py index a6b905e..e39d289 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -748,11 +748,10 @@ Currently the magic system has the following functions:\n""" """ user_ns = self.shell.user_ns - internal_ns = self.shell.internal_ns user_ns_hidden = self.shell.user_ns_hidden out = [ i for i in user_ns if not i.startswith('_') \ - and not (i in internal_ns or i in user_ns_hidden) ] + and not i in user_ns_hidden ] typelist = parameter_s.split() if typelist: diff --git a/IPython/core/prefilter.py b/IPython/core/prefilter.py index 6b423e7..feba34d 100644 --- a/IPython/core/prefilter.py +++ b/IPython/core/prefilter.py @@ -86,7 +86,7 @@ def is_shadowed(identifier, ip): than ifun, because it can not contain a '.' character.""" # This is much safer than calling ofind, which can change state return (identifier in ip.user_ns \ - or identifier in ip.internal_ns \ + or identifier in ip.user_global_ns \ or identifier in ip.ns_table['builtin']) diff --git a/IPython/core/tests/test_iplib.py b/IPython/core/tests/test_iplib.py index 6a23e15..713e532 100644 --- a/IPython/core/tests/test_iplib.py +++ b/IPython/core/tests/test_iplib.py @@ -33,7 +33,7 @@ def test_reset(): """reset must clear most namespaces.""" # The number of variables in the private user_ns_hidden is not zero, but it # should be constant regardless of what we do - nvars_config_ns = len(ip.user_ns_hidden) + nvars_hidden = len(ip.user_ns_hidden) # Check that reset runs without error ip.reset() @@ -49,15 +49,8 @@ def test_reset(): # Finally, check that all namespaces have only as many variables as we # expect to find in them: - for ns in ip.ns_refs_table: - if ns is ip.user_ns: - nvars_expected = nvars_user_ns - elif ns is ip.user_ns_hidden: - nvars_expected = nvars_config_ns - else: - nvars_expected = 0 - - yield nt.assert_equals(len(ns), nvars_expected) + yield nt.assert_equals(len(ip.user_ns), nvars_expected) + yield nt.assert_equals(len(ip.user_ns_hidden), nvars_hidden) # Tests for reporting of exceptions in various modes, handling of SystemExit,