[Zope-dev] Intercepting __getattr__ in a Python 2.3 old-style mixin class?

Andreas Jung lists at zopyx.com
Mon Nov 7 13:01:55 CET 2016

I have a large Python 2.3 based installation with 200k LOC. As part of a migration project I need to intercept all attribute lookups of all old-style class.

Old legacy code:

    class Foo(Bar):

My idea is to inject a common mixin class like

    class Foo(Bar, Mixin):

    class Mixin:

        def __getattr__(self, k)
           print repr(self), k
           return Foo.__getattr__(self, k)

However I am running always into a recursion because Foo.__getattr__ resolves to Mixin.__getattr__.
(The migrated code has to run under Python 2.3 as the first step of the migration where will be moving
forward to Python 2.7 later on).

Is there any way to fix the code for Python 2.3 old-style classes?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 618 bytes
Desc: OpenPGP digital signature
URL: <http://mail.zope.org/pipermail/zope-dev/attachments/20161107/b5200b90/attachment.sig>

More information about the Zope-Dev mailing list