##// END OF EJS Templates
Remove extraneous internal_ns and ns_refs_table variables.
Thomas Kluyver -
Show More
@@ -903,10 +903,6 b' class InteractiveShell(SingletonConfigurable, Magic):'
903 903 # doesn't need to be separately tracked in the ns_table.
904 904 self.user_ns_hidden = set()
905 905
906 # A namespace to keep track of internal data structures to prevent
907 # them from cluttering user-visible stuff. Will be updated later
908 self.internal_ns = {}
909
910 906 # Now that FakeModule produces a real module, we've run into a nasty
911 907 # problem: after script execution (via %run), the module where the user
912 908 # code ran is deleted. Now that this object is a true module (needed
@@ -940,18 +936,9 b' class InteractiveShell(SingletonConfigurable, Magic):'
940 936 # introspection facilities can search easily.
941 937 self.ns_table = {'user_global':self.user_module.__dict__,
942 938 'user_local':user_ns,
943 'internal':self.internal_ns,
944 939 'builtin':builtin_mod.__dict__
945 940 }
946 941
947 # Similarly, track all namespaces where references can be held and that
948 # we can safely clear (so it can NOT include builtin). This one can be
949 # a simple list. Note that the main execution namespaces, user_ns and
950 # user_global_ns, can NOT be listed here, as clearing them blindly
951 # causes errors in object __del__ methods. Instead, the reset() method
952 # clears them manually and carefully.
953 self.ns_refs_table = [ self.internal_ns, self._main_ns_cache ]
954
955 942 @property
956 943 def user_global_ns(self):
957 944 return self.user_module.__dict__
@@ -1085,10 +1072,6 b' class InteractiveShell(SingletonConfigurable, Magic):'
1085 1072 if self.displayhook.do_full_cache:
1086 1073 self.displayhook.flush()
1087 1074
1088 # Restore the user namespaces to minimal usability
1089 for ns in self.ns_refs_table:
1090 ns.clear()
1091
1092 1075 # The main execution namespaces must be cleared very carefully,
1093 1076 # skipping the deletion of the builtin-related keys, because doing so
1094 1077 # would cause errors in many object's __del__ methods.
@@ -1128,9 +1111,9 b' class InteractiveShell(SingletonConfigurable, Magic):'
1128 1111 """
1129 1112 if varname in ('__builtin__', '__builtins__'):
1130 1113 raise ValueError("Refusing to delete %s" % varname)
1131 ns_refs = self.ns_refs_table + [self.user_ns,
1132 self.user_global_ns, self._user_main_module.__dict__] +\
1133 self._main_ns_cache.values()
1114
1115 ns_refs = [self.user_ns, self.user_global_ns,
1116 self._user_main_module.__dict__] + self._main_ns_cache.values()
1134 1117
1135 1118 if by_name: # Delete by name
1136 1119 for ns in ns_refs:
@@ -1172,7 +1155,7 b' class InteractiveShell(SingletonConfigurable, Magic):'
1172 1155 raise TypeError('regex must be a string or compiled pattern')
1173 1156 # Search for keys in each namespace that match the given regex
1174 1157 # If a match is found, delete the key/value pair.
1175 for ns in self.ns_refs_table:
1158 for ns in [self.user_ns, self.user_global_ns]:
1176 1159 for var in ns:
1177 1160 if m.search(var):
1178 1161 del ns[var]
@@ -1266,7 +1249,7 b' class InteractiveShell(SingletonConfigurable, Magic):'
1266 1249 # Put them in a list. The order is important so that we
1267 1250 # find things in the same order that Python finds them.
1268 1251 namespaces = [ ('Interactive', self.user_ns),
1269 ('IPython internal', self.internal_ns),
1252 ('Interactive (global)', self.user_global_ns),
1270 1253 ('Python builtin', builtin_mod.__dict__),
1271 1254 ('Alias', self.alias_manager.alias_table),
1272 1255 ]
@@ -748,11 +748,10 b' Currently the magic system has the following functions:\\n"""'
748 748 """
749 749
750 750 user_ns = self.shell.user_ns
751 internal_ns = self.shell.internal_ns
752 751 user_ns_hidden = self.shell.user_ns_hidden
753 752 out = [ i for i in user_ns
754 753 if not i.startswith('_') \
755 and not (i in internal_ns or i in user_ns_hidden) ]
754 and not i in user_ns_hidden ]
756 755
757 756 typelist = parameter_s.split()
758 757 if typelist:
@@ -86,7 +86,7 b' def is_shadowed(identifier, ip):'
86 86 than ifun, because it can not contain a '.' character."""
87 87 # This is much safer than calling ofind, which can change state
88 88 return (identifier in ip.user_ns \
89 or identifier in ip.internal_ns \
89 or identifier in ip.user_global_ns \
90 90 or identifier in ip.ns_table['builtin'])
91 91
92 92
@@ -33,7 +33,7 b' def test_reset():'
33 33 """reset must clear most namespaces."""
34 34 # The number of variables in the private user_ns_hidden is not zero, but it
35 35 # should be constant regardless of what we do
36 nvars_config_ns = len(ip.user_ns_hidden)
36 nvars_hidden = len(ip.user_ns_hidden)
37 37
38 38 # Check that reset runs without error
39 39 ip.reset()
@@ -49,15 +49,8 b' def test_reset():'
49 49
50 50 # Finally, check that all namespaces have only as many variables as we
51 51 # expect to find in them:
52 for ns in ip.ns_refs_table:
53 if ns is ip.user_ns:
54 nvars_expected = nvars_user_ns
55 elif ns is ip.user_ns_hidden:
56 nvars_expected = nvars_config_ns
57 else:
58 nvars_expected = 0
59
60 yield nt.assert_equals(len(ns), nvars_expected)
52 yield nt.assert_equals(len(ip.user_ns), nvars_expected)
53 yield nt.assert_equals(len(ip.user_ns_hidden), nvars_hidden)
61 54
62 55
63 56 # Tests for reporting of exceptions in various modes, handling of SystemExit,
General Comments 0
You need to be logged in to leave comments. Login now