diff --git a/IPython/Shell.py b/IPython/Shell.py index 9c46fa8..5b3ce1b 100644 --- a/IPython/Shell.py +++ b/IPython/Shell.py @@ -4,7 +4,7 @@ All the matplotlib support code was co-developed with John Hunter, matplotlib's author. -$Id: Shell.py 958 2005-12-27 23:17:51Z fperez $""" +$Id: Shell.py 964 2005-12-28 21:03:01Z fperez $""" #***************************************************************************** # Copyright (C) 2001-2004 Fernando Perez @@ -47,10 +47,10 @@ USE_TK = False class IPShell: """Create an IPython instance.""" - def __init__(self,argv=None,user_ns=None,debug=1, - shell_class=InteractiveShell): - self.IP = make_IPython(argv,user_ns=user_ns,debug=debug, - shell_class=shell_class) + def __init__(self,argv=None,user_ns=None,user_global_ns=None, + debug=1,shell_class=InteractiveShell): + self.IP = make_IPython(argv,user_ns=user_ns,user_global_ns=user_global_ns, + debug=debug,shell_class=shell_class) def mainloop(self,sys_exit=0,banner=None): self.IP.mainloop(banner) @@ -261,10 +261,11 @@ class MTInteractiveShell(InteractiveShell): # from the pygtk mailing list, to avoid lockups with system calls. def __init__(self,name,usage=None,rc=Struct(opts=None,args=None), - user_ns = None, banner2='',**kw): + user_ns=None,user_global_ns=None,banner2='',**kw): """Similar to the normal InteractiveShell, but with threading control""" - IPython.iplib.InteractiveShell.__init__(self,name,usage,rc,user_ns,banner2) + InteractiveShell.__init__(self,name,usage,rc,user_ns, + user_global_ns,banner2) # Locking control variable self.thread_ready = threading.Condition() @@ -475,17 +476,19 @@ class MatplotlibShell(MatplotlibShellBase,InteractiveShell): """Single-threaded shell with matplotlib support.""" def __init__(self,name,usage=None,rc=Struct(opts=None,args=None), - user_ns = None, **kw): + user_ns=None,user_global_ns=None,**kw): user_ns,b2 = self._matplotlib_config(name) - InteractiveShell.__init__(self,name,usage,rc,user_ns,banner2=b2,**kw) + InteractiveShell.__init__(self,name,usage,rc,user_ns,user_global_ns, + banner2=b2,**kw) class MatplotlibMTShell(MatplotlibShellBase,MTInteractiveShell): """Multi-threaded shell with matplotlib support.""" def __init__(self,name,usage=None,rc=Struct(opts=None,args=None), - user_ns = None, **kw): + user_ns=None,user_global_ns=None, **kw): user_ns,b2 = self._matplotlib_config(name) - MTInteractiveShell.__init__(self,name,usage,rc,user_ns,banner2=b2,**kw) + MTInteractiveShell.__init__(self,name,usage,rc,user_ns,user_global_ns, + banner2=b2,**kw) #----------------------------------------------------------------------------- # Utility functions for the different GUI enabled IPShell* classes. @@ -581,8 +584,8 @@ class IPShellGTK(threading.Thread): TIMEOUT = 100 # Millisecond interval between timeouts. - def __init__(self,argv=None,user_ns=None,debug=1, - shell_class=MTInteractiveShell): + def __init__(self,argv=None,user_ns=None,user_global_ns=None, + debug=1,shell_class=MTInteractiveShell): import gtk @@ -595,7 +598,9 @@ class IPShellGTK(threading.Thread): if gtk.pygtk_version >= (2,4,0): mainquit = self.gtk.main_quit else: mainquit = self.gtk.mainquit - self.IP = make_IPython(argv,user_ns=user_ns,debug=debug, + self.IP = make_IPython(argv,user_ns=user_ns, + user_global_ns=user_global_ns, + debug=debug, shell_class=shell_class, on_kill=[mainquit]) @@ -656,8 +661,8 @@ class IPShellWX(threading.Thread): TIMEOUT = 100 # Millisecond interval between timeouts. - def __init__(self,argv=None,user_ns=None,debug=1, - shell_class=MTInteractiveShell): + def __init__(self,argv=None,user_ns=None,user_global_ns=None, + debug=1,shell_class=MTInteractiveShell): import wxPython.wx as wx @@ -668,7 +673,9 @@ class IPShellWX(threading.Thread): # Allows us to use both Tk and GTK. self.tk = get_tk() - self.IP = make_IPython(argv,user_ns=user_ns,debug=debug, + self.IP = make_IPython(argv,user_ns=user_ns, + user_global_ns=user_global_ns, + debug=debug, shell_class=shell_class, on_kill=[self.wxexit]) # HACK: slot for banner in self; it will be passed to the mainloop @@ -738,8 +745,8 @@ class IPShellQt(threading.Thread): TIMEOUT = 100 # Millisecond interval between timeouts. - def __init__(self,argv=None,user_ns=None,debug=0, - shell_class=MTInteractiveShell): + def __init__(self,argv=None,user_ns=None,user_global_ns=None, + debug=0,shell_class=MTInteractiveShell): import qt @@ -761,7 +768,9 @@ class IPShellQt(threading.Thread): # Allows us to use both Tk and QT. self.tk = get_tk() - self.IP = make_IPython(argv,user_ns=user_ns,debug=debug, + self.IP = make_IPython(argv,user_ns=user_ns, + user_global_ns=user_global_ns, + debug=debug, shell_class=shell_class, on_kill=[qt.qApp.exit]) @@ -809,32 +818,36 @@ class IPShellMatplotlib(IPShell): Having this on a separate class simplifies the external driver code.""" - def __init__(self,argv=None,user_ns=None,debug=1): - IPShell.__init__(self,argv,user_ns,debug,shell_class=MatplotlibShell) + def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1): + IPShell.__init__(self,argv,user_ns,user_global_ns,debug, + shell_class=MatplotlibShell) class IPShellMatplotlibGTK(IPShellGTK): """Subclass IPShellGTK with MatplotlibMTShell as the internal shell. Multi-threaded class, meant for the GTK* backends.""" - def __init__(self,argv=None,user_ns=None,debug=1): - IPShellGTK.__init__(self,argv,user_ns,debug,shell_class=MatplotlibMTShell) + def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1): + IPShellGTK.__init__(self,argv,user_ns,user_global_ns,debug, + shell_class=MatplotlibMTShell) class IPShellMatplotlibWX(IPShellWX): """Subclass IPShellWX with MatplotlibMTShell as the internal shell. Multi-threaded class, meant for the WX* backends.""" - def __init__(self,argv=None,user_ns=None,debug=1): - IPShellWX.__init__(self,argv,user_ns,debug,shell_class=MatplotlibMTShell) + def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1): + IPShellWX.__init__(self,argv,user_ns,user_global_ns,debug, + shell_class=MatplotlibMTShell) class IPShellMatplotlibQt(IPShellQt): """Subclass IPShellQt with MatplotlibMTShell as the internal shell. Multi-threaded class, meant for the Qt* backends.""" - def __init__(self,argv=None,user_ns=None,debug=1): - IPShellQt.__init__(self,argv,user_ns,debug,shell_class=MatplotlibMTShell) + def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1): + IPShellQt.__init__(self,argv,user_ns,user_global_ns,debug, + shell_class=MatplotlibMTShell) #----------------------------------------------------------------------------- # Factory functions to actually start the proper thread-aware shell diff --git a/IPython/completer.py b/IPython/completer.py index d8f340c..23acd6a 100644 --- a/IPython/completer.py +++ b/IPython/completer.py @@ -103,12 +103,13 @@ class Completer: readline.set_completer(Completer(my_namespace).complete) """ - - if namespace and type(namespace) != types.DictType: - raise TypeError,'namespace must be a dictionary' - if global_namespace and type(global_namespace) != types.DictType: - raise TypeError,'global_namespace must be a dictionary' + # some minimal strict typechecks. For some core data structures, I + # want actual basic python types, not just anything that looks like + # one. This is especially true for namespaces. + for ns in (namespace,global_namespace): + if ns is not None and type(ns) != types.DictType: + raise TypeError,'namespace must be a dictionary' # Don't bind to namespace quite yet, but flag whether the user wants a # specific namespace or to use __main__.__dict__. This will allow us @@ -518,6 +519,8 @@ class IPCompleter(Completer): except IndexError: return None except: - #import traceback; traceback.print_exc() # dbg + #from IPython.ultraTB import AutoFormattedTB; # dbg + #tb=AutoFormattedTB('Verbose');tb() #dbg + # If completion fails, don't annoy the user. return None diff --git a/IPython/iplib.py b/IPython/iplib.py index 4784297..33ce52a 100644 --- a/IPython/iplib.py +++ b/IPython/iplib.py @@ -6,7 +6,7 @@ Requires Python 2.1 or newer. This file contains all the classes and helper functions specific to IPython. -$Id: iplib.py 963 2005-12-28 19:21:29Z fperez $ +$Id: iplib.py 964 2005-12-28 21:03:01Z fperez $ """ #***************************************************************************** @@ -236,6 +236,13 @@ class InteractiveShell(Logger, Magic): user_ns = None,user_global_ns=None,banner2='', custom_exceptions=((),None),embedded=False): + # some minimal strict typechecks. For some core data structures, I + # want actual basic python types, not just anything that looks like + # one. This is especially true for namespaces. + for ns in (user_ns,user_global_ns): + if ns is not None and type(ns) != types.DictType: + raise TypeError,'namespace must be a dictionary' + # Put a reference to self in builtins so that any form of embedded or # imported code can test for being inside IPython. __builtin__.__IPYTHON__ = self diff --git a/IPython/ipmaker.py b/IPython/ipmaker.py index 4d6559f..746b609 100644 --- a/IPython/ipmaker.py +++ b/IPython/ipmaker.py @@ -6,7 +6,7 @@ Requires Python 2.1 or better. This file contains the main make_IPython() starter function. -$Id: ipmaker.py 963 2005-12-28 19:21:29Z fperez $""" +$Id: ipmaker.py 964 2005-12-28 21:03:01Z fperez $""" #***************************************************************************** # Copyright (C) 2001-2004 Fernando Perez. @@ -55,8 +55,9 @@ from IPython.Prompts import CachedOutput from IPython.genutils import * #----------------------------------------------------------------------------- -def make_IPython(argv=None,user_ns=None,debug=1,rc_override=None, - shell_class=InteractiveShell,embedded=False,**kw): +def make_IPython(argv=None,user_ns=None,user_global_ns=None,debug=1, + rc_override=None,shell_class=InteractiveShell, + embedded=False,**kw): """This is a dump of IPython into a single function. Later it will have to be broken up in a sensible manner. @@ -86,7 +87,8 @@ def make_IPython(argv=None,user_ns=None,debug=1,rc_override=None, # __IP.name. We set its name via the first parameter passed to # InteractiveShell: - IP = shell_class('__IP',user_ns=user_ns,embedded=embedded,**kw) + IP = shell_class('__IP',user_ns=user_ns,user_global_ns=user_global_ns, + embedded=embedded,**kw) # Put 'help' in the user namespace from site import _Helper diff --git a/doc/ChangeLog b/doc/ChangeLog index d84fb07..297d516 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -5,6 +5,7 @@ questions part 2 - \/ characters revisited' on the iypthon user list: http://scipy.net/pipermail/ipython-user/2005-June/000907.html + (InteractiveShell.__init__): fix tab-completion bug in threaded shells. * IPython/ipmaker.py (make_IPython): make the autoedit_syntax flag true by default, and add it to the shipped ipythonrc file. Since