seg fault on asscessing undefined attr in __getattr__

Fredrik Aronsson d98aron at dtek.chalmers.se
Fri May 25 16:07:10 EDT 2001


In article <mailman.990786458.26390.python-list at python.org>,
	Oleg Broytmann <phd at phd.fep.ru> writes:
> On Fri, 25 May 2001, Kong-Jei Kuan wrote:
>> hi, i am still using python 1.52, and don't know if this happens to other
>> versions, can some verify this?
>>
>> Python 1.5.2 (#0, Dec 27 2000, 13:59:38)  [GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2
>> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>> >>> class A:
>> ...   def __getattr__(self, name):
>> ...     self.x
>> ...
>> >>> a=A()
>> >>> a
>> Segmentation fault
> 
>    Do you understand you've put your Python into infinite recursion?
> 
> Oleg.

... and to break it you could for example do 

class A:
    def __getattr__(self, name):
        try:
            return self.__dict__[name]
        except KeyError:
            raise AttributeError # to make hasattr happy...

/Fredrik



More information about the Python-list mailing list