diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 0b6c771..e1f67c7 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -881,8 +881,7 @@ class InteractiveShell(SingletonConfigurable, Magic): #------------------------------------------------------------------------- # Things related to IPython's various namespaces #------------------------------------------------------------------------- - default_user_ns = True - default_user_module = True + default_user_namespaces = True def init_create_namespaces(self, user_module=None, user_ns=None): # Create the namespace where the user will operate. user_ns is @@ -921,10 +920,8 @@ class InteractiveShell(SingletonConfigurable, Magic): # These routines return a properly built module and dict as needed by # the rest of the code, and can also be used by extension writers to # generate properly initialized namespaces. - if user_ns is not None: - self.default_user_ns = False - if user_module is not None: - self.default_user_module = False + if (user_ns is not None) or (user_module is not None): + self.default_user_namespaces = False self.user_module, self.user_ns = self.prepare_user_module(user_module, user_ns) # A record of hidden variables we have added to the user namespace, so diff --git a/IPython/frontend/terminal/embed.py b/IPython/frontend/terminal/embed.py index a4359d6..ea6214d 100644 --- a/IPython/frontend/terminal/embed.py +++ b/IPython/frontend/terminal/embed.py @@ -172,12 +172,12 @@ class InteractiveShellEmbed(TerminalInteractiveShell): there is no fundamental reason why it can't work perfectly.""" # Get locals and globals from caller - if local_ns is None or module is None: + if (local_ns is None or module is None) and self.default_user_namespaces: call_frame = sys._getframe(stack_depth).f_back - if local_ns is None and self.default_user_ns: + if local_ns is None: local_ns = call_frame.f_locals - if module is None and self.default_user_module: + if module is None: global_ns = call_frame.f_globals module = sys.modules[global_ns['__name__']]