From 5411be822c7463d180cb458abc5b1f1f8c19559e Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Thu, 14 Apr 2011 22:12:34 +0100 Subject: [PATCH] Objects can still be pickled after a %reset. --- IPython/core/interactiveshell.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index da0425e2cb6..17beb89166e 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -1059,17 +1059,13 @@ def reset(self, new_session=True): # Restore the user namespaces to minimal usability for ns in self.ns_refs_table: ns.clear() - - # In some situations, e.g. testing, our fake main module has a __dict__ - # separate from the user_ns: if so, we need to clear it manually. - if self.user_ns is not self.user_ns_mod.__dict__: - self.user_ns_mod.__dict__.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. for ns in [self.user_ns, self.user_global_ns]: drop_keys = set(ns.keys()) + drop_keys.discard('__name__') drop_keys.discard('__builtin__') drop_keys.discard('__builtins__') for k in drop_keys: @@ -1077,6 +1073,11 @@ def reset(self, new_session=True): # Restore the user namespaces to minimal usability self.init_user_ns() + + # In some situations, e.g. testing, our fake main module has a __dict__ + # separate from the user_ns: if so, we need to clear it manually. + if self.user_ns is not self.user_ns_mod.__dict__: + init_fakemod_dict(self.user_ns_mod, self.user_ns) # Restore the default and user aliases self.alias_manager.clear_aliases()