Ben Finney wrote:
Ethan Furman <et...@stoneleaf.us> writes:

Why is NoneType unable to produce a None instance? I realise that None
is a singleton

That answers your question. Because None is a singleton, the job of its
type is to make sure there are no other instances.

Which it can do quite easily by returning the single instance of None -- it is not necessary to raise an exception to fulfill its duty.


but so are True and False, and bool is able to handle returning them:

Well, they don't meet the definition of a singleton, because there are
two instances of ‘bool’ :-)

Okay, a slightly relaxed definition of singleton, since there is only ever one instance with the value of True, or the value of False; likewise, there is only ever one instance with the value of None.


This feels like a violation of 'Special cases aren't special enough to
break the rules.'

In the case of ‘bool’, the rule was broken before being introduced.

I think we disagree on what the rule is. I see it as "Return an instance if you can." Nobody has yet pointed out a good reason on why NoneType, NotImplementedType, and ellipsis (to be thorough ;) cannot or should not return the single instance that exists, when every other built-in will return either a new object, or the single object that exists for that value.

~Ethan~

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to