<div dir="ltr"><div>Hi Andreas,</div><div><br></div><div>As Hanno said, you'll still be in old-style-classes-land even in Python 2.7 unless you inherit from `object` directly.</div><div><br></div><div>You said:</div><div><br></div><div><pre style="white-space:pre-wrap;color:rgb(0,0,0)"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">My idea is to inject a common mixin class like
    class Foo(Bar, Mixin):<br>        ...
    class Mixin:
        def __getattr__(self, k)<br>           print repr(self), k<br>           return Foo.__getattr__(self, k)</blockquote></pre></div><div class="gmail_extra"><br></div><div class="gmail_extra">Your recursion error is caused by calling `Foo.__getattr__(self, k)` from `Mixin`, but `Foo` inherits from `Mixin`. Calling a method of a subclass from the same-named method in the superclass is a recurssion.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Instead `Mixin` needs to call `Bar.__getattr__` since `Bar` is the superclass to `Foo`.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Alternatively, if you don't want to name any specific superclass inside the mixin method, (and since you can't use `super()` since you're using old-style classes), I suggest a different approach. Instead of a mixin class, use a method factory, like this:</div><div class="gmail_extra"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font face="monospace, monospace">def my__getattr__factory(SuperClass):<br></font><font face="monospace, monospace">    def __getattr__(self, k):<br></font><font face="monospace, monospace">        print repr(self), k<br></font><font face="monospace, monospace">        return SuperClass.__getattr__(self, k)</font></blockquote><div class="gmail_extra"><br></div><div class="gmail_extra">Which you can then use as:</div><div class="gmail_extra"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font face="monospace, monospace">class Foo(Bar):  # <- No mixin</font> </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font face="monospace, monospace"><br></font><font face="monospace, monospace">    __getattr__ = my_getattr__generator(Bar)  # <- Bar, not F</font>oo</blockquote><div class="gmail_extra"><br></div><div class="gmail_extra">Regards,</div><div class="gmail_extra"><br></div><div class="gmail_extra">Leo</div><div class="gmail_extra"><br><div class="gmail_quote">On 7 November 2016 at 12:29, Hanno Schlichting <span dir="ltr"><<a href="mailto:hanno@hannosch.eu" target="_blank">hanno@hannosch.eu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Mon, Nov 7, 2016, at 14:01, Andreas Jung wrote:<br>
> Python 2.7 is different because all classes are automatically new-style<br>
> classes.<br>
> In Python 2.7 you would have to overwrite __getattribute__() but I am on<br>
> Python 2.3 here.<br>
<br>
No :)<br>
<br>
In Python 3 all classes are new-style classes. In Python 2 (including<br>
2.7) you have to be explicit and either inherit from object (new-style)<br>
or not (old-style).<br>
<br>
In Python 2.7 you get:<br>
<br>
>>> class A: pass<br>
>>> class B(object): pass<br>
>>> type(A)<br>
<type 'classobj'><br>
>>> type(B)<br>
<type 'type'><br>
<br>
In Python 3 both are of type 'type'.<br>
<br>
And only new-style classes use '__getattribute__'. '__getattr__' is the<br>
right approach for old-style classes in any Python 2 version, even in<br>
Python 2.7.<br>
<br>
Hanno<br>
______________________________<wbr>_________________<br>
Zope-Dev maillist  -  <a href="mailto:Zope-Dev@zope.org">Zope-Dev@zope.org</a><br>
<a href="https://mail.zope.org/mailman/listinfo/zope-dev" rel="noreferrer" target="_blank">https://mail.zope.org/mailman/<wbr>listinfo/zope-dev</a><br>
**  No cross posts or HTML encoding!  **<br>
(Related lists -<br>
 <a href="https://mail.zope.org/mailman/listinfo/zope-announce" rel="noreferrer" target="_blank">https://mail.zope.org/mailman/<wbr>listinfo/zope-announce</a><br>
 <a href="https://mail.zope.org/mailman/listinfo/zope" rel="noreferrer" target="_blank">https://mail.zope.org/mailman/<wbr>listinfo/zope</a> )<br>
</blockquote></div><br></div></div>