[Python-Dev] NoneType(None) raises exception

Ethan Furman ethan at stoneleaf.us
Fri Apr 26 02:43:21 CEST 2013


On 04/25/2013 05:27 PM, Steven D'Aprano wrote:
> On 26/04/13 09:56, MRAB wrote:
>> On the other hand:
>>
>>      type(value)(value) == value
>>
>> would return True for the built-in types (will certain exceptions, such
>> as when value is float("NaN")).
>
> Not an exception, that works fine in 3.3:
>
>>>> value = float('nan')
>>>> type(value)(value)
> nan

You missed the == part:

>>> type(value)(value) == value
False

>> Let's ask the Zen:
>>
>> Special cases aren't special enough to break the rules.
>>
>> Although practicality beats purity.
>
>
> I cannot think of any use-case where I would actively want
> NoneType(None) to fail. That would be like having bool(True)
> raise an exception.
>
> On the other hand, NoneType(x) for any other x ought to fail.

Or, since the purpose of NoneType is to return None, just return None no matter what!

Kind'a like 0 * anything == 0.

--
~Ethan~


More information about the Python-Dev mailing list