On Thu, Apr 4, 2013 at 1:50 PM, Tim Delaney <tim.dela...@aptare.com> wrote:
> I fall into:
>
> 1. int(), float(), str() etc should return that exact class (and
> operator.index() should return exactly an int).
>
> 2. It could sometimes be useful for __int__() and __index__() to return a
> subclass of int.
>
> So, for the int constructor, I would have the following logic (assume
> appropriate try/catch):
>
> def __new__(cls, obj):
>     i = obj.__int__()
>
>     if type(i) is int:
>         return i
>
>     return i._internal_value

CPython can solve this in C using an unsafe cast, and the code that
checks for allowable subclasses of int actually ensures such a cast
will work. But it still feels wrong; __int__ should be expected to do
the work.

--
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to