Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


psearch: TypeError: expected string or buffer #129

yarikoptic opened this Issue · 3 comments

2 participants


version: 0.10-2 (Debian sid)
original report:

I've ran into this issue many times and finally decided to report ;)

In [1]: import numpy

In [2]: %psearch numpy..s

TypeError Traceback (most recent call last)


/usr/lib/pymodules/python2.5/IPython/wildcard.pyc in glob_filter(lista, name_pattern, hidehidden, ignore_case)
113 else:
114 reg=re.compile(pattern+"$")
--> 115 result=[x for x in lista if reg.match(x) and show_hidden(x,hidehidden)]
116 return result
117 ns=self._ns

TypeError: expected string or buffer

happens with
ipdb> p lista
[, , 'f4', , 'f8', , 'Complex128', , , 'Bool', 'b1', , 'String0', 'q', , 'Complex64', 'G', 'u4', , 'Unicode0', 'u1', , 'u2', 'i1', 'UInt16', 'Float32', , 'Int64', , 'c16', '?', 'Void0', , 'i8', , 'B', 'D', , 'F', 'I', 'H', 'i2', , 'L', 'O', 'i4', 'Q', 'S', 'c8', 'U', 'Int8', 'Complex32', 'V', , , 'u8', 'UInt64', 'Float64', 'b', 'd', 'g', 'f', 'i', 'h', 'UInt8', 'l', 'UInt32', 'Object0', , 'Float128', , 'c32', 'f16', 'Int16', , 'Int32']

ipdb> reg.match(lista[0])
*** TypeError: expected string or buffer

I guess safest way would be to check first if x is a string at all ;)


Right, from the debian bug report, the command that triggered this is %psearch numpy.*.*s, although it's been mangled by the formatting here. The simplest way to replicate is:

a = {1:""}
%psearch a.*

Specifically, the problem is in utils.wildcard. When instantiating a NameSpace, objects are inspected by the dir2 function to produce a dictionary of their attributes. Dictionaries, however, are special cased, since the main namespaces are passed as dictionaries; they are used directly, rather than listing their attributes. So it's wrong whenever it constructs a namespace for a dictionary, but it will only throw an error if the dictionary has non-string keys.

I'm attempting to find an elegant solution.


The test, the fix, and the general tidy-up of the IPython.utils.wildcard module are in a sequence of commits at:


Merge branch 'issue-129'

closed by 26fb955
closed by 26fb955

@markvoorhies markvoorhies referenced this issue from a commit in markvoorhies/ipython
@takluyver takluyver Merge branch 'issue-129'
closes gh-129
closes gh-251
@ellisonbg ellisonbg referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@dwrensha dwrensha referenced this issue from a commit
@andrewrk andrewrk ability to attach and detach encoder and player
 * admin option to disable and enable hardware playback. Closes #129
 * only attach encoder when streamers are connected. Closes #143
@mattvonrocketstein mattvonrocketstein referenced this issue from a commit in mattvonrocketstein/ipython
@takluyver takluyver Merge branch 'issue-129'
closes gh-129
closes gh-251
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.