##// 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 # doesn't need to be separately tracked in the ns_table.
903 # doesn't need to be separately tracked in the ns_table.
904 self.user_ns_hidden = set()
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 # Now that FakeModule produces a real module, we've run into a nasty
906 # Now that FakeModule produces a real module, we've run into a nasty
911 # problem: after script execution (via %run), the module where the user
907 # problem: after script execution (via %run), the module where the user
912 # code ran is deleted. Now that this object is a true module (needed
908 # code ran is deleted. Now that this object is a true module (needed
@@ -940,17 +936,8 b' class InteractiveShell(SingletonConfigurable, Magic):'
940 # introspection facilities can search easily.
936 # introspection facilities can search easily.
941 self.ns_table = {'user_global':self.user_module.__dict__,
937 self.ns_table = {'user_global':self.user_module.__dict__,
942 'user_local':user_ns,
938 'user_local':user_ns,
943 'internal':self.internal_ns,
944 'builtin':builtin_mod.__dict__
939 'builtin':builtin_mod.__dict__
945 }
940 }
946
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
941
955 @property
942 @property
956 def user_global_ns(self):
943 def user_global_ns(self):
@@ -1085,10 +1072,6 b' class InteractiveShell(SingletonConfigurable, Magic):'
1085 if self.displayhook.do_full_cache:
1072 if self.displayhook.do_full_cache:
1086 self.displayhook.flush()
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 # The main execution namespaces must be cleared very carefully,
1075 # The main execution namespaces must be cleared very carefully,
1093 # skipping the deletion of the builtin-related keys, because doing so
1076 # skipping the deletion of the builtin-related keys, because doing so
1094 # would cause errors in many object's __del__ methods.
1077 # would cause errors in many object's __del__ methods.
@@ -1128,10 +1111,10 b' class InteractiveShell(SingletonConfigurable, Magic):'
1128 """
1111 """
1129 if varname in ('__builtin__', '__builtins__'):
1112 if varname in ('__builtin__', '__builtins__'):
1130 raise ValueError("Refusing to delete %s" % varname)
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()
1134
1114
1115 ns_refs = [self.user_ns, self.user_global_ns,
1116 self._user_main_module.__dict__] + self._main_ns_cache.values()
1117
1135 if by_name: # Delete by name
1118 if by_name: # Delete by name
1136 for ns in ns_refs:
1119 for ns in ns_refs:
1137 try:
1120 try:
@@ -1172,7 +1155,7 b' class InteractiveShell(SingletonConfigurable, Magic):'
1172 raise TypeError('regex must be a string or compiled pattern')
1155 raise TypeError('regex must be a string or compiled pattern')
1173 # Search for keys in each namespace that match the given regex
1156 # Search for keys in each namespace that match the given regex
1174 # If a match is found, delete the key/value pair.
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 for var in ns:
1159 for var in ns:
1177 if m.search(var):
1160 if m.search(var):
1178 del ns[var]
1161 del ns[var]
@@ -1266,7 +1249,7 b' class InteractiveShell(SingletonConfigurable, Magic):'
1266 # Put them in a list. The order is important so that we
1249 # Put them in a list. The order is important so that we
1267 # find things in the same order that Python finds them.
1250 # find things in the same order that Python finds them.
1268 namespaces = [ ('Interactive', self.user_ns),
1251 namespaces = [ ('Interactive', self.user_ns),
1269 ('IPython internal', self.internal_ns),
1252 ('Interactive (global)', self.user_global_ns),
1270 ('Python builtin', builtin_mod.__dict__),
1253 ('Python builtin', builtin_mod.__dict__),
1271 ('Alias', self.alias_manager.alias_table),
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 user_ns = self.shell.user_ns
750 user_ns = self.shell.user_ns
751 internal_ns = self.shell.internal_ns
752 user_ns_hidden = self.shell.user_ns_hidden
751 user_ns_hidden = self.shell.user_ns_hidden
753 out = [ i for i in user_ns
752 out = [ i for i in user_ns
754 if not i.startswith('_') \
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 typelist = parameter_s.split()
756 typelist = parameter_s.split()
758 if typelist:
757 if typelist:
@@ -86,7 +86,7 b' def is_shadowed(identifier, ip):'
86 than ifun, because it can not contain a '.' character."""
86 than ifun, because it can not contain a '.' character."""
87 # This is much safer than calling ofind, which can change state
87 # This is much safer than calling ofind, which can change state
88 return (identifier in ip.user_ns \
88 return (identifier in ip.user_ns \
89 or identifier in ip.internal_ns \
89 or identifier in ip.user_global_ns \
90 or identifier in ip.ns_table['builtin'])
90 or identifier in ip.ns_table['builtin'])
91
91
92
92
@@ -33,7 +33,7 b' def test_reset():'
33 """reset must clear most namespaces."""
33 """reset must clear most namespaces."""
34 # The number of variables in the private user_ns_hidden is not zero, but it
34 # The number of variables in the private user_ns_hidden is not zero, but it
35 # should be constant regardless of what we do
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 # Check that reset runs without error
38 # Check that reset runs without error
39 ip.reset()
39 ip.reset()
@@ -49,15 +49,8 b' def test_reset():'
49
49
50 # Finally, check that all namespaces have only as many variables as we
50 # Finally, check that all namespaces have only as many variables as we
51 # expect to find in them:
51 # expect to find in them:
52 for ns in ip.ns_refs_table:
52 yield nt.assert_equals(len(ip.user_ns), nvars_expected)
53 if ns is ip.user_ns:
53 yield nt.assert_equals(len(ip.user_ns_hidden), nvars_hidden)
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)
61
54
62
55
63 # Tests for reporting of exceptions in various modes, handling of SystemExit,
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