[Python-Dev] SWIG and rlcompleter

Fernando Perez fperez.net at gmail.com
Tue Aug 16 19:08:59 CEST 2005

Michael Hudson wrote:

> jepler at unpythonic.net writes:
>> You don't need something like a buggy SWIG to put non-strings in dir().
>>>>> class C: pass
>> ...
>>>>> C.__dict__[3] = "bad wolf"
>>>>> dir(C)
>> [3, '__doc__', '__module__']
>> This is likely to happen "legitimately", for instance in a class that allows
>> x.y and x['y'] to mean the same thing. (if the user assigns to x[3])
> I wonder if dir() should strip non-strings?

Me too.  And it would be a good idea, I think, to specify explicitly in the
dir() docs this behavior.  Right now at least rlcompleter and ipython's
completer can break due to this, there may be other tools out there with
similar problems.

If  it's a stated design goal that dir() can return non-strings, that's fine.  I
can filter them out in my completion code.  I'd just like to know what the
official stance on dir()'s return values is.



More information about the Python-Dev mailing list