The Python namedtuple
factory function allows the name of the subclass it creates to be specified twice — first on the left side of the declaration and then as the first argument of the function (IPython 1.0.0, Python 3.3.1):
In [1]: from collections import namedtuple
In [2]: TypeName = namedtuple('OtherTypeName', ['item'])
All the examples I've seen on the docs.python.org site use an identical name in both positions. But it's possible to use different names, and they function differently:
In [3]: TypeName(1)
Out[3]: OtherTypeName(item=1)
In [4]: type(TypeName)
Out[4]: builtins.type
In [5]: type(OtherTypeName)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-8-6616c1214742> in <module>()
----> 1 type(OtherTypeName)
NameError: name 'OtherTypeName' is not defined
In []: OtherTypeName(1)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-9-47d6b5709a5c> in <module>()
----> 1 OtherTypeName(1)
NameError: name 'OtherTypeName' is not defined
I'm wondering what applications there might be for this functionality.