##// END OF EJS Templates
Simplify logic for deciding when to auto-detect local namespace and module.
Thomas Kluyver -
Show More
@@ -881,8 +881,7 b' class InteractiveShell(SingletonConfigurable, Magic):'
881 #-------------------------------------------------------------------------
881 #-------------------------------------------------------------------------
882 # Things related to IPython's various namespaces
882 # Things related to IPython's various namespaces
883 #-------------------------------------------------------------------------
883 #-------------------------------------------------------------------------
884 default_user_ns = True
884 default_user_namespaces = True
885 default_user_module = True
886
885
887 def init_create_namespaces(self, user_module=None, user_ns=None):
886 def init_create_namespaces(self, user_module=None, user_ns=None):
888 # Create the namespace where the user will operate. user_ns is
887 # Create the namespace where the user will operate. user_ns is
@@ -921,10 +920,8 b' class InteractiveShell(SingletonConfigurable, Magic):'
921 # These routines return a properly built module and dict as needed by
920 # These routines return a properly built module and dict as needed by
922 # the rest of the code, and can also be used by extension writers to
921 # the rest of the code, and can also be used by extension writers to
923 # generate properly initialized namespaces.
922 # generate properly initialized namespaces.
924 if user_ns is not None:
923 if (user_ns is not None) or (user_module is not None):
925 self.default_user_ns = False
924 self.default_user_namespaces = False
926 if user_module is not None:
927 self.default_user_module = False
928 self.user_module, self.user_ns = self.prepare_user_module(user_module, user_ns)
925 self.user_module, self.user_ns = self.prepare_user_module(user_module, user_ns)
929
926
930 # A record of hidden variables we have added to the user namespace, so
927 # A record of hidden variables we have added to the user namespace, so
@@ -172,12 +172,12 b' class InteractiveShellEmbed(TerminalInteractiveShell):'
172 there is no fundamental reason why it can't work perfectly."""
172 there is no fundamental reason why it can't work perfectly."""
173
173
174 # Get locals and globals from caller
174 # Get locals and globals from caller
175 if local_ns is None or module is None:
175 if (local_ns is None or module is None) and self.default_user_namespaces:
176 call_frame = sys._getframe(stack_depth).f_back
176 call_frame = sys._getframe(stack_depth).f_back
177
177
178 if local_ns is None and self.default_user_ns:
178 if local_ns is None:
179 local_ns = call_frame.f_locals
179 local_ns = call_frame.f_locals
180 if module is None and self.default_user_module:
180 if module is None:
181 global_ns = call_frame.f_globals
181 global_ns = call_frame.f_globals
182 module = sys.modules[global_ns['__name__']]
182 module = sys.modules[global_ns['__name__']]
183
183
General Comments 0
You need to be logged in to leave comments. Login now