proxy class and __add__ method

M

Magnus Schuster

Hello,
I have written the following small proxy class which I expect to pass all
function calls to the 'original' object:

--- BEGIN ---
class proxy(object):
def __init__( self, subject ):
self.__subject = subject
def __getattr__( self, name ):
return getattr( self.__subject, name )

prx_i=proxy(1)
print hasattr(prx_i,'__add__')
j=prx_i.__add__(1)
k=prx_i+1
--- END ---

Actually the "hasattr(prx_i,'__add__')" returns "True" as expected, and
"j=prx_i.__add__(1)" sets j=2.

But "k=prx_i+1" raises a
<type 'exceptions.TypeError'>: unsupported operand type(s) for +: 'proxy'
and 'int'.

How is this addition different from the previous line "j=..."? And how can I
modify the proxy class so that all methods are passed on, which are not
explicitly overloaded?

Regards,
Magnus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top