type(None)()

Robert Kern robert.kern at gmail.com
Thu Aug 16 16:56:53 CEST 2012


On 8/16/12 2:56 PM, Ian Kelly wrote:
> On Thu, Aug 16, 2012 at 6:47 AM, Hans Mulder <hansmu at xs4all.nl> wrote:
>> On 8/08/12 04:14:01, Steven D'Aprano wrote:
>>> NoneType raises an error if you try to create a second instance. bool
>>> just returns one of the two singletons (doubletons?) again.
>>>
>>> py> type(None)()
>>> Traceback (most recent call last):
>>>    File "<stdin>", line 1, in <module>
>>> TypeError: cannot create 'NoneType' instances
>>
>> Why is that?
>>
>> Why doesn't it just return an existing instance of the type,
>> like bool, int, str and other built-in non-mutable types do?
>
> Because unlike those other types there is no use case for that.  It's
> simpler to raise an error.

What are the use cases for the empty-argument versions of bool(), int(), 
float(), and str()?

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list