<br><br><div class="gmail_quote">On 19 November 2011 23:11, Vinay Sajip <span dir="ltr">&lt;<a href="mailto:vinay_sajip@yahoo.co.uk">vinay_sajip@yahoo.co.uk</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">Michael Foord &lt;fuzzyman &lt;at&gt; <a href="http://voidspace.org.uk" target="_blank">voidspace.org.uk</a>&gt; writes:<br>
<br>
&gt; That works fine in Python 3 (mock.Mock does it):<br>
&gt;<br>
&gt;  &gt;&gt;&gt; class Foo(object):<br>
&gt; ...  @property<br>
&gt; ...  def __class__(self):<br>
&gt; ...   return int<br>
&gt; ...<br>
&gt;  &gt;&gt;&gt; a = Foo()<br>
&gt;  &gt;&gt;&gt; isinstance(a, int)<br>
&gt; True<br>
&gt;  &gt;&gt;&gt; a.__class__<br>
&gt; &lt;class &#39;int&#39;&gt;<br>
&gt;<br>
&gt; There must be something else going on here.<br>
&gt;<br>
<br>
</div>Michael, thanks for the quick response. Okay, I&#39;ll dig in a bit further: the<br>
definition in SimpleLazyObject is<br>
<br>
__class__ = property(new_method_proxy(operator.attrgetter(&quot;__class__&quot;)))<br>
<br>
so perhaps the problem is something related to the specifics of the definition.<br>
Here&#39;s what I found in initial exploration:<br>
<br>
--------------------------------------------------------------------------<br>
Python 2.7.2+ (default, Oct 4 2011, 20:06:09)<br>
[GCC 4.6.1] on linux2<br>
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<br>
&gt;&gt;&gt; from django.utils.functional import SimpleLazyObject<br>
&gt;&gt;&gt; fake_bool = SimpleLazyObject(lambda: True)<br>
&gt;&gt;&gt; fake_bool.__class__<br>
&lt;type &#39;bool&#39;&gt;<br>
&gt;&gt;&gt; fake_bool.__dict__<br>
{&#39;_setupfunc&#39;: &lt;function &lt;lambda&gt; at 0xca9ed8&gt;, &#39;_wrapped&#39;: True}<br>
&gt;&gt;&gt; SimpleLazyObject.__dict__<br>
dict_proxy({<br>
    &#39;__module__&#39;: &#39;django.utils.functional&#39;,<br>
    &#39;__nonzero__&#39;: &lt;function inner at 0xca9de8&gt;,<br>
    &#39;__deepcopy__&#39;: &lt;function __deepcopy__ at 0xca9c08&gt;,<br>
    &#39;__str__&#39;: &lt;function inner at 0xca9b18&gt;,<br>
    &#39;_setup&#39;: &lt;function _setup at 0xca9aa0&gt;,<br>
    &#39;__class__&#39;: &lt;property object at 0xca5730&gt;,<br>
    &#39;__hash__&#39;: &lt;function inner at 0xca9d70&gt;,<br>
    &#39;__unicode__&#39;: &lt;function inner at 0xca9b90&gt;,<br>
    &#39;__bool__&#39;: &lt;function inner at 0xca9de8&gt;,<br>
    &#39;__eq__&#39;: &lt;function inner at 0xca9cf8&gt;,<br>
    &#39;__doc__&#39;: &#39;\n A lazy object initialised from any function.\n\n<br>
        Designed for compound objects of unknown type. For builtins or<br>
        objects of\n known type, use django.utils.functional.lazy.\n &#39;,<br>
    &#39;__init__&#39;: &lt;function __init__ at 0xca9a28&gt;<br>
})<br>
--------------------------------------------------------------------------<br>
Python 3.2.2 (default, Sep 5 2011, 21:17:14)<br>
[GCC 4.6.1] on linux2<br>
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<br>
&gt;&gt;&gt; from django.utils.functional import SimpleLazyObject<br>
&gt;&gt;&gt; fake_bool = SimpleLazyObject(lambda : True)<br>
&gt;&gt;&gt; fake_bool.__class__<br>
&lt;class &#39;django.utils.functional.SimpleLazyObject&#39;&gt;<br>
&gt;&gt;&gt; fake_bool.__dict__<br>
{<br>
    &#39;_setupfunc&#39;: &lt;function &lt;lambda&gt; at 0x1c36ea8&gt;,<br>
    &#39;_wrapped&#39;: &lt;object object at 0x1d88b70&gt;<br>
}<br>
&gt;&gt;&gt; SimpleLazyObject.__dict__<br>
dict_proxy({<br>
    &#39;__module__&#39;: &#39;django.utils.functional&#39;,<br>
    &#39;__nonzero__&#39;: &lt;function inner at 0x1f56490&gt;,<br>
    &#39;__deepcopy__&#39;: &lt;function __deepcopy__ at 0x1f562f8&gt;,<br>
    &#39;__str__&#39;: &lt;function inner at 0x1f561e8&gt;,<br>
    &#39;_setup&#39;: &lt;function _setup at 0x1f56160&gt;,<br>
    &#39;__hash__&#39;: &lt;function inner at 0x1f56408&gt;,<br>
    &#39;__unicode__&#39;: &lt;function inner at 0x1f56270&gt;,<br>
    &#39;__bool__&#39;: &lt;function inner at 0x1f56490&gt;,<br>
    &#39;__eq__&#39;: &lt;function inner at 0x1f56380&gt;,<br>
    &#39;__doc__&#39;: &#39;\n A lazy object initialised from any function.\n\n<br>
        Designed for compound objects of unknown type. For builtins or<br>
        objects of\n known type, use django.utils.functional.lazy.\n &#39;,<br>
    &#39;__init__&#39;: &lt;function __init__ at 0x1f560d8&gt;<br>
})<br>
--------------------------------------------------------------------------<br>
<br>
In Python 3, there&#39;s no __class__ property as there is in Python 2,<br>
the fake_bool&#39;s type isn&#39;t bool, and the callable to set up the wrapped<br>
object never gets called (which is why _wrapped is not set to True, but to<br>
an anonymous object - this is set in SimpleLazyObject.__init__).<br>
<br></blockquote><div><br>The Python compiler can do strange things with assignment to __class__ in the presence of super. This issue has now been fixed, but it may be what is biting you:<br><br>    <a href="http://bugs.python.org/issue12370">http://bugs.python.org/issue12370</a><br>
<br>If this *is* the problem, then see the workaround suggested in the issue. (alias super to _super in the module scope and use the old style super calling convention.)<br><br>Michael<br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

Puzzling!<br>
<br>
Regards,<br>
<font color="#888888"><br>
Vinay Sajip<br>
</font><div><div></div><div class="h5"><br>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-dev" target="_blank">http://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk" target="_blank">http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk</a><br>
<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><pre cols="72"><a href="http://www.voidspace.org.uk/" target="_blank">http://www.voidspace.org.uk/</a><br><br>May you do good and not evil<br>May you find forgiveness for yourself and forgive others<br>
May you share freely, never taking more than you give.<br>-- the sqlite blessing <a href="http://www.sqlite.org/different.html" target="_blank">http://www.sqlite.org/different.html</a></pre>
<br>