<p dir="ltr"><br>
On 5 Apr 2013 01:07, "Chris Angelico" <<a href="mailto:rosuav@gmail.com">rosuav@gmail.com</a>> wrote:<br>
><br>
> On Fri, Apr 5, 2013 at 1:59 AM, Guido van Rossum <<a href="mailto:guido@python.org">guido@python.org</a>> wrote:<br>
> > On Thu, Apr 4, 2013 at 7:47 AM, Chris Angelico <<a href="mailto:rosuav@gmail.com">rosuav@gmail.com</a>> wrote:<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>
> ><br>
> ><br>
> > A class can define a __new__ method that returns a different object. E.g.<br>
> > (python 3):<br>
> ><br>
><br>
> Right, I'm aware it's possible. But who would expect it of a class?</p>
<p dir="ltr">Python 3.3 does it for OSError to map errno values to the appropriate subclasses. That's mainly to aid migration to the new exception structure, though (see PEP 3151). For a clean slate API design you would use a separate factory function or class method to do the conversion.</p>

<p dir="ltr">Cheers,<br>
Nick.</p>
<p dir="ltr">><br>
> ChrisA<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">http://mail.python.org/mailman/listinfo/python-dev</a><br>
> Unsubscribe: <a href="http://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com">http://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com</a><br>
</p>