##// END OF EJS Templates
Simplify logic (semantics unchanged) in builtins trap.
Fernando Perez -
Show More
@@ -88,13 +88,8 b' class BuiltinTrap(Configurable):'
88 self._orig_builtins[key] = orig
88 self._orig_builtins[key] = orig
89 bdict[key] = value
89 bdict[key] = value
90
90
91 def remove_builtin(self, key):
91 def remove_builtin(self, key, orig):
92 """Remove an added builtin and re-set the original."""
92 """Remove an added builtin and re-set the original."""
93 try:
94 orig = self._orig_builtins.pop(key)
95 except KeyError:
96 pass
97 else:
98 if orig is BuiltinUndefined:
93 if orig is BuiltinUndefined:
99 del __builtin__.__dict__[key]
94 del __builtin__.__dict__[key]
100 else:
95 else:
@@ -115,11 +110,9 b' class BuiltinTrap(Configurable):'
115 def deactivate(self):
110 def deactivate(self):
116 """Remove any builtins which might have been added by add_builtins, or
111 """Remove any builtins which might have been added by add_builtins, or
117 restore overwritten ones to their previous values."""
112 restore overwritten ones to their previous values."""
118 # Note: must iterate over a static keys() list because we'll be
119 # mutating the dict itself
120 remove_builtin = self.remove_builtin
113 remove_builtin = self.remove_builtin
121 for key in self._orig_builtins.keys():
114 for key, val in self._orig_builtins.iteritems():
122 remove_builtin(key)
115 remove_builtin(key, val)
123 self._orig_builtins.clear()
116 self._orig_builtins.clear()
124 self._builtins_added = False
117 self._builtins_added = False
125 try:
118 try:
General Comments 0
You need to be logged in to leave comments. Login now