[Python-ideas] change NoneType, NotImplementedType, & ellipses to return the appropriate singleton
Masklinn
masklinn at masklinn.net
Sun Aug 7 18:46:53 CEST 2011
On 2011-08-07, at 18:37 , David Townshend wrote:
> Is there any reason not to allow similar behaviour for True and False? i.e.
> True() == True
As far as I undersand, that's not the proposal for NoneType (or NotImplementedType or ellipsis) at all.
You're suggesting that the *value* could be callable (and return itself), the proposal is about *types*, and them becoming "normal" (callable) types: currently, if you get a hold of NoneType, NotImplementedType or ellipsis (generally via a call to `type`) you can not use it to get an instance of that class back:
>>> type(None)()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot create 'NoneType' instances
>>> type(NotImplemented)()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot create 'NotImplementedType' instances
>>> type(...)()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot create 'ellipsis' instances
This proposal is merely about removing this forbidding.
Booleans don't have this issue: `bool` is already a normal (callable) type, and returns `False` when called without arguments.
More information about the Python-ideas
mailing list