From 49a413e66bf5a29b21ea4d41be899ba38624e02e 2005-11-13 10:21:08 From: fperez Date: 2005-11-13 10:21:08 Subject: [PATCH] wildcard fixes for subclasses --- diff --git a/IPython/Magic.py b/IPython/Magic.py index 9664073..bad50e7 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Magic functions for InteractiveShell. -$Id: Magic.py 919 2005-10-15 07:57:05Z fperez $""" +$Id: Magic.py 922 2005-11-13 10:21:08Z fperez $""" #***************************************************************************** # Copyright (C) 2001 Janko Hauser and @@ -816,7 +816,7 @@ Currently the magic system has the following functions:\n""" array_type = Numeric.ArrayType.__name__ # Find all variable names and types so we can figure out column sizes - get_vars = lambda i: self.locals[i] + get_vars = lambda i: self.shell.user_ns[i] type_name = lambda v: type(v).__name__ varlist = map(get_vars,varnames) typelist = map(type_name,varlist) @@ -871,8 +871,9 @@ Currently the magic system has the following functions:\n""" if not ans.lower() == 'y': print 'Nothing done.' return + user_ns = self.shell.user_ns for i in self.magic_who_ls(): - del(self.locals[i]) + del(user_ns[i]) def magic_config(self,parameter_s=''): """Show IPython's internal configuration.""" diff --git a/IPython/OInspect.py b/IPython/OInspect.py index a93a3ed..6cd81b7 100644 --- a/IPython/OInspect.py +++ b/IPython/OInspect.py @@ -6,7 +6,7 @@ Uses syntax highlighting for presenting the various information elements. Similar in spirit to the inspect module, but all calls take a name argument to reference the name under which an object is being read. -$Id: OInspect.py 919 2005-10-15 07:57:05Z fperez $ +$Id: OInspect.py 922 2005-11-13 10:21:08Z fperez $ """ #***************************************************************************** @@ -398,45 +398,45 @@ class Inspector: page(output) # end pinfo - def psearch(self,oname='',formatter = None,shell=None): - """Search namespaces with wildcards for objects. + def psearch(self,oname='',formatter=None,shell=None): + """Search namespaces with wildcards for objects. Optional arguments: - - oname: rest of the commandline containging pattern and options - - - formatter: Not used - - - shell: The shell object from the Magic class. Needed to - access the namespaces - - """ - option_list=["-c","-a"] - import pdb -# pdb.set_trace() - cmds=oname.split() - filter="" - type_pattern="all" - ns_cmds=[] - options=[x for x in cmds if x in option_list] - ignorecase="-c" not in options - showhidden="-a" in options - ns_cmds=[x for x in cmds if x[0] in "-+" and x not in option_list] - cmds=[x for x in cmds if x[0] not in "-+"] - if len(cmds)>2: #assume we want to choose name spaces. - #Rather poor design forces the use of a typepattern in order to choose name spaces - cmds=cmds[:2] - if len(cmds)==2: - filter,type_pattern=cmds - elif len(cmds)==1: - filter=cmds[0].strip() - - do_list=choose_namespaces(shell,ns_cmds) - - search_result=[] - for ns in do_list: - tmp_res=list(list_namespace(ns,type_pattern,filter,ignorecase=ignorecase,showhidden=showhidden)) - search_result.extend(tmp_res) - search_result.sort() - - page("\n".join(search_result)) + - oname: rest of the commandline containging pattern and options. + + - formatter: Not used. + + - shell: The shell object from the Magic class. Needed to access + the namespaces. + """ + option_list = ['-c','-a'] + cmds = oname.split() + filter = '' + type_pattern = 'all' + options = [x for x in cmds if x in option_list] + ignorecase = '-c' not in options + showhidden = '-a' in options + ns_cmds = [x for x in cmds if x[0] in '-+' and x not in option_list] + cmds = [x for x in cmds if x[0] not in '-+'] + len_cmds = len(cmds) + if len_cmds == 1: + filter = cmds[0].strip() + elif len_cmds == 2: + filter,type_pattern = cmds + elif len_cmds>2: + # assume we want to choose name spaces. Rather poor design forces + #the use of a typepattern in order to choose name spaces + cmds = cmds[:2] + + do_list = choose_namespaces(shell,ns_cmds) + + search_result = [] + for ns in do_list: + tmp_res = list(list_namespace(ns,type_pattern,filter, + ignorecase=ignorecase, + showhidden=showhidden)) + search_result.extend(tmp_res) + search_result.sort() + + page('\n'.join(search_result)) diff --git a/IPython/wildcard.py b/IPython/wildcard.py index 29e30ec..617d14c 100644 --- a/IPython/wildcard.py +++ b/IPython/wildcard.py @@ -69,19 +69,18 @@ class NameSpace(object): on name and types""" def __init__(self,obj,namepattern="*",typepattern="all",ignorecase=True, showhidden=True): - self.showhidden=showhidden #Hide names beginning with single _ - self.object=obj - self.namepattern=namepattern - self.typepattern=typepattern - self.ignorecase=ignorecase - if type(obj)==type(dict()): - self._ns=obj + self.showhidden = showhidden #Hide names beginning with single _ + self.object = obj + self.namepattern = namepattern + self.typepattern = typepattern + self.ignorecase = ignorecase + + # We should only match EXACT dicts here, so DON'T use isinstance() + if type(obj) == types.DictType: + self._ns = obj else: - try: - self._ns=self.object.__dict__ - except exceptions.AttributeError: - self._ns=dict([(key,getattr(self.object,key)) - for key in dir(self.object)]) + self._ns = dict([(key,getattr(obj,key)) for key in dir(obj) + if isinstance(key, basestring)]) def get_ns(self): """Return name space dictionary with objects matching type and name patterns.""" diff --git a/doc/ChangeLog b/doc/ChangeLog index 3c256df..e30fdc6 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,9 @@ +2005-11-13 + + * IPython/wildcard.py (NameSpace.__init__): fix resolution of + attributes in wildcard searches for subclasses. Modified version + of a patch by Jorgen. + 2005-11-12 * IPython/iplib.py (embed_mainloop): Fix handling of globals for