Why this doesn't work?

mk mrkafk at gmail.com
Thu Feb 18 18:28:44 CET 2010


Sorry to bother everyone again, but I have this problem bugging me:

#!/usr/bin/python -i

class Foo(object):

     def nostat(self,val):
         print val

     nostat.__orig_get__ = nostat.__get__

     @staticmethod
     def nostatget(*args, **kwargs):
         print 'args:', args, 'kwargs:', kwargs
         nostat.__orig_get__(*args, **kwargs)

     nostat.__get__ = nostatget
     setattr(nostat,'__get__',nostatget)


f = Foo()

f.nostat('a')

print f.nostat.__get__ is f.nostat.__orig_get__


This produces:

a
False

I expected to see 'nostatget' output: nostat.__get__ = nostatget 
obviously failed to replace this function's __get__ method.

The question is why? Isn't __get__ a normal attribute of a function nostat?

This is made so much weirder that nostat.__get__ is no longer original 
__get__, so it looks like it should have been replaced, but if so, why 
nostatget doesn't get called?

Regards,
mk






More information about the Python-list mailing list