[Python-bugs-list] [ python-Bugs-752543 ] error with __getattr__

SourceForge.net noreply@sourceforge.net
Wed, 11 Jun 2003 05:31:28 -0700


Bugs item #752543, was opened at 2003-06-11 13:39
Message generated for change (Comment added) made by doerwalter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=752543&group_id=5470

Category: Windows
Group: Python 2.2.3
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Uwe Matthaeus (cptncrunch)
Assigned to: Tim Peters (tim_one)
Summary: error with __getattr__

Initial Comment:
This is the design pattern proxy:

class Implementierung2:

    def a(self): print 'a';
    def b(self): print 'b';
    def c(self): print 'c';

class Proxy:

    def __init__(self):
        self.__impl = Implementierung2();

    def __getattr__(self,name):
        return getattr(self.__imp,name);

if __name__ == '__main__':

    p = Proxy();
    p.a();

error message(s):

File "f:\python\proxy.py", line 17, in __getattr__
    return getattr(self.__imp,name);

RuntimeError: maximum recursion depth exceeded

See Bruce Eckel: 'Thinking in python'

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

>Comment By: Walter Dörwald (doerwalter)
Date: 2003-06-11 14:31

Message:
Logged In: YES 
user_id=89016

This is caused by a typo in your constructor: Instead of
self.__impl = Implementierung2()
use
self.__imp = Implementierung2()
and it will work.

BTW, you should drop the semicolons, they are useless.


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

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