@@ -335,22 +335,38 @@ def attr_matches(self, text):
335335type_ = type (obj )
336336f = None
337337# Dark magic:
338+ # If __getattribute__ doesn't exist on the class and __getattr__ does
339+ # then __getattr__ will be called when doing
340+ # getattr(type_, '__getattribute__', None)
341+ # so we need to first remove the __getattr__, then the
342+ # __getattribute__, then look up the attributes and then restore the
343+ # original methods. :-(
344+ # The upshot being that introspecting on an object to display its
345+ # attributes will avoid unwanted side-effects.
338346if type_ != types .InstanceType :
339- f = getattr (type_ ,'__getattribute__' ,None )
340- if f is not None :
347+ __getattr__ = getattr (type_ ,'__getattr__' ,None )
348+ if __getattr__ is not None :
349+ try :
350+ setattr (type_ ,'__getattr__' , (lambda _ :None ))
351+ except TypeError :
352+ __getattr__ = None
353+ __getattribute__ = getattr (type_ ,'__getattribute__' ,None )
354+ if __getattribute__ is not None :
341355try :
342356setattr (type_ ,'__getattribute__' ,object .__getattribute__ )
343357except TypeError :
344358# XXX: This happens for e.g. built-in types
345- f = None
359+ __getattribute__ = None
346360# /Dark magic
347361
348362try :
349363matches = self .attr_lookup (obj ,expr ,attr )
350364finally :
351365# Dark magic:
352- if f is not None :
353- setattr (type_ ,'__getattribute__' ,f )
366+ if __getattribute__ is not None :
367+ setattr (type_ ,'__getattribute__' ,__getattribute__ )
368+ if __getattr__ is not None :
369+ setattr (type_ ,'__getattr__' ,__getattr__ )
354370# /Dark magic
355371return matches
356372
@@ -519,7 +535,6 @@ def _complete(self, unused_tab=False):
519535try :
520536self .completer .complete (cw ,0 )
521537except Exception :
522- raise
523538# This sucks, but it's either that or list all the exceptions that could
524539# possibly be raised here, so if anyone wants to do that, feel free to send me
525540# a patch. XXX: Make sure you raise here if you're debugging the completion