[IPython-User] Tab completion doesn't work on class/instance where __getattr__ has been overridden

Jeremy Conlin jlconlin@gmail....
Tue Mar 1 16:55:54 CST 2011

On Tue, Mar 1, 2011 at 3:11 PM, Jörgen Stenarson
<jorgen.stenarson@bostream.nu> wrote:
> Jeremy Conlin skrev 2011-03-01 20:58:
>> I have a class (subclassed from list) where I have overwridden the
>> __getattr__ method as:
>>      def __getattr__(self, name):
>>          if name.startswith("__"): raise AttributeError
>>          def _multiplexed(*args, **kwargs):
>>              return [getattr(R, name)(*args, **kwargs) for R in self]
>>          return _multiplexed
>> Now when I try to use tab completion, iPython just beeps at me and
>> doesn't complete anything.  If I remove this method from my class, I
>> can do tab completion.
>> Does the tab completion use __getattr__ somewhere?  Can I add
>> something to my definition to make tab completion work in iPython?
> One way to customize which attributes are found by the completer is to
> define the __dir__ method which essentially defines what should be
> returned by a dir call.

I tried defining __dir__ in my class as:

    def __dir__(self):
        heritage = dir(super(self.__class__, self)) # inherited attributes
        return sorted(heritage + self.__class__.__dict__.keys() +

(I found this example on
 However I still didn't get tab completion.  I can call
dir(objectInstance) and get a list of methods and attributes.  I can
call dir(objectInstance) when without __dir__ being defined and also
get a list of methods and attributes.

Any other ideas?

More information about the IPython-User mailing list