Permalink
Browse files

Remove extraneous internal_ns and ns_refs_table variables.

  • Loading branch information...
1 parent ef23c60 commit 6e69f60b69bed0fd933dcbae2ba7acadb75fd832 @takluyver committed Jul 30, 2011
Showing with 10 additions and 35 deletions.
  1. +5 −22 IPython/core/interactiveshell.py
  2. +1 −2 IPython/core/magic.py
  3. +1 −1 IPython/core/prefilter.py
  4. +3 −10 IPython/core/tests/test_iplib.py
@@ -903,10 +903,6 @@ def init_create_namespaces(self, user_module=None, user_ns=None):
# 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 @@ def init_create_namespaces(self, user_module=None, user_ns=None):
# 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 @@ def reset(self, new_session=True):
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 @@ def del_var(self, varname, by_name=False):
"""
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 @@ def reset_selective(self, regex=None):
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 @@ def _ofind(self, oname, namespaces=None):
# 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),
]
View
@@ -748,11 +748,10 @@ def magic_who_ls(self, parameter_s=''):
"""
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:
@@ -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'])
@@ -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,

0 comments on commit 6e69f60

Please sign in to comment.