[IronPython] __getattribute__ bug

Michael Foord fuzzyman at gmail.com
Mon Nov 12 15:08:21 CET 2007


There as no answer to this - so I have raised it as codeplex issue
13820:

Michael
http://www.manning.com/foord

On Nov 3, 12:26 am, Michael Foord <fuzzy... at voidspace.org.uk> wrote:
> Hello all,
>
> A bug in '__getattribute__' - magic methods should be fetched from the
> class and not go through '__getattribute__'.
>
> This is making a proxy class I'm writing behave very oddly:
>
> The following code:
>
> def DoNothing(*args):
>     pass
>
> class Something(object):
>     def __getattribute__(self, name):
>         print name
>         return DoNothing
>
>     def __call__(self):
>         print 'called'
>
>     def __getitem__(self, name):
>         raise Exception('w00t!')
>
>     def __setitem__(self, name, value):
>         raise Exception('w00t!')
>
> s = Something()
> s['fish'] = 3
>
> Does this on CPython:
>
> C:\compile\cext\trunk\cext>descriptors.py
> Traceback (most recent call last):
>   File "C:\compile\cext\trunk\cext\descriptors.py", line 20, in ?
>     s['fish'] = 3
>   File "C:\compile\cext\trunk\cext\descriptors.py", line 17, in __setitem__
>     raise Exception('w00t!')
> Exception: w00t!
>
> And this on IronPython 2a5:
>
> C:\compile\cext\trunk\cext>C:\compile\IronPython2\ipy.exe -D
> -X:TabCompletion -X
> :ColorfulConsole descriptors.py
> __setitem__
>
> To make things odder - if the class 'Something' doesn't have a
> __setitem__ method then an attribute error is correctly raised. For
> '__call__' I am *sometimes* seeing that go through '__getattribute__'
> and sometimes not...
>
> Michaelhttp://www.manning.com/foord
>
> _______________________________________________
> Users mailing list
> Us... at lists.ironpython.comhttp://lists.ironpython.com/listinfo.cgi/users-ironpython.com




More information about the Ironpython-users mailing list