Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

psearch: TypeError: expected string or buffer #129

Closed
yarikoptic opened this Issue · 3 comments

2 participants

@yarikoptic

version: 0.10-2 (Debian sid)
original report: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=565351

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 ;)

@takluyver
Owner

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.

@takluyver
Owner

The test, the fix, and the general tidy-up of the IPython.utils.wildcard module are in a sequence of commits at:
https://github.com/takowl/ipython/tree/issue-129

@takluyver
Owner

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
26fb955
@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
9093517
@mattvonrocketstein mattvonrocketstein referenced this issue from a commit in mattvonrocketstein/ipython
@takluyver takluyver Merge branch 'issue-129'
closes gh-129
closes gh-251
11328bd
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.