[IronPython] Overloading __getattr__

Michael Foord michael.foord at resolversystems.com
Fri Jun 16 17:02:40 CEST 2006


Hello all,

We have a problem with IronPython and overloading __getattr__, and use 
of the python magic methods (double underscore).

To illustrate the problem :

class Test(object):
    def __getattr__(self, name):
        print name
        raise AttributeError("Go Away")

if Test():
    print "Hello"
   
On CPython it does this :

Hello

On IronPython :

__nonzero__
Traceback (most recent call last):
  File C:\Personal\Python Projects\modules in 
progress\ironpython\test.py, line
6, in Initialize
  File C:\Personal\Python Projects\modules in 
progress\ironpython\test.py, line
4, in __getattr__
AttributeError: Go Away

We are trying to overload __getattr__ and getting calls to __hash__, 
__len__, __gt__ etc sent there in various places.

All the best,

Michael Foord
http://www.resolversystems.com





More information about the Ironpython-users mailing list