[IPython-dev] wildcard patch

Jörgen Stenarson jorgen.stenarson at bostream.nu
Sat Nov 12 05:38:07 CST 2005


Hi,

I have discovered a problem with the wildcard functionality.

As it is written now it will only match attributes in an object that are
present in its __dict__, and only if there is no __dict__ for the object 
it builds one by calling dir(object). This means inherited attributes 
will not be visible for objects with a __dict__. Which means there will 
be a mismatch between the results you get using dir(object) compared to 
?object.*

An example of this problem can be found by subclassing dict

In [1]:class test(dict):
    ...:    pass
    ...:

In [2]:x=test(a=1)

In [3]:x
Out[3]:{'a': 1}

Without patch
In [4]:?x.*

With patch
In [4]:?x.*
x.__class__
x.__cmp__
x.__contains__
x.__delattr__
+many more

The attached patch builds the namespace by calling dir on all objects,
this should make the wildcard search more consistent with dir. But the
operation of dir is not well specified and may change between releases 
of python. So if someone feels the operation of ?* should be more well 
defined I'm open to suggestions on how to go about that.

/Jörgen





-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: wildcard-patch-20051112
Url: http://projects.scipy.org/pipermail/ipython-dev/attachments/20051112/61f11125/attachment.pl 


More information about the IPython-dev mailing list