Consider:
Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
--> for ins in ({0:'0'}, (1,), set([2, 3]), [4, 5], 6, 'seven',
... 8.0, True, None):
... print(type(ins))
... type(ins)()
...
{}
()
set()
[]
0
''
0.0
False
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
TypeError: cannot create 'NoneType' instances
I hit this issue when I had a dictionary of types to instantiate, one of
which was NoneType.
Is there any reason why we shouldn't change these three to produce the
singleton instance instead of raising an error?
Pro: They would then be consistent with every other built-in which will
return either a new instance (int, str, float, etc), or the singleton
instance that already exists (bool, and sometimes int & str), as well as
no longer needing the `lambda:None` workaround (or worse, a try-except
if you don't know what types are coming in).
Con: Might be code that relies on the exception being raised -- is
anybody aware of any?
~Ethan~