[Python-bugs-list] [ python-Bugs-532646 ] Recursive class instance "error"

noreply@sourceforge.net noreply@sourceforge.net
Thu, 21 Mar 2002 01:47:10 -0800


Bugs item #532646, was opened at 2002-03-20 10:56
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=532646&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Gregor Mirai (gregmi)
Assigned to: Nobody/Anonymous (nobody)
Summary: Recursive class instance "error"

Initial Comment:
If one writes the following code (tested on Python  
2.1, 2.2 on platforms MacOS X Server, MacOS X, Windows 
98, NT, 2000) one can easily produce several "errors".

MacOS X, MacOS X Server (Python 2.1, 2.2)
------------------------------------------
class A:
   def __getattr__(self, name):
     print name,
     return A()
------------------------------------------

>>> a=A()
>>> a.foo
Segmentation fault

Win98, NT, 2000 (Python 2.1, 2.2)
------------------------------------------
class A:
   def __getattr__(self, name):
     print name
     return A()
------------------------------------------

>>> a=A()
>>> a.foo
foo
__repr__ __call__ __call__ __call__ ... ad inf



----------------------------------------------------------------------

Comment By: Nobody/Anonymous (nobody)
Date: 2002-03-21 01:47

Message:
Logged In: NO 

>>> a=A() 
>>> a.foo 
foo 
__repr__ __call__ __call__ __call__ ... ad inf

This is normal behavior. The code at the top is buggy. The 
correct one is:

class A:
  def __getattr__(self, name):
    if name == '__repr__':
      return self.__repr__()
    print name
    return A()

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-03-20 14:10

Message:
Logged In: YES 
user_id=6380

This is buggy user code.

But the segfault should be fixed if possible.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=532646&group_id=5470