<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Apr 4, 2013 at 7:47 AM, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</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"><div class="im">On Fri, Apr 5, 2013 at 1:23 AM, Oscar Benjamin<br>
<<a href="mailto:oscar.j.benjamin@gmail.com">oscar.j.benjamin@gmail.com</a>> wrote:<br>
> The reason for calling int(obj) is to get an object that is precisely<br>
> of type int. When I call this I do not want any modified or additional<br>
> methods or data attached to the resulting object.<br>
<br>
</div>There's something I'm fundamentally not understanding about this<br>
debate, and that is: How is it that calling a class can logically<br>
return anything other than an instance of that class? Taking it to a<br>
user-defined type:<br>
<br>
class Foo:<br>
    pass<br>
<br>
class Bar(Foo):<br>
    pass<br>
<br>
Is there any argument that I can pass to Foo() to get back a Bar()?<br>
Would anyone expect there to be one? Sure, I could override __new__ to<br>
do stupid things, but in terms of logical expectations, I'd expect<br>
that Foo(x) will return a Foo object, not a Bar object. Why should int<br>
be any different? What have I missed here?<br></blockquote><div> </div></div>A class can define a __new__ method that returns a different object. E.g. (python 3):<br><br>>>> class C:<br>...   def __new__(cls): return 42<br>

... <br>>>> C()<br>42<br>>>> <br><br clear="all"></div><div class="gmail_extra"><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)
</div></div>