Is there an usage `_tuple` in python?
Question: I read the official documentation for `collections.namedtuple` today and found
`_tuple` mentioned in the `__new__` method. I did not find where the `_tuple`
defined.

Here is the code, you can try it in Python - it does not raise any error.

    
    
    >>> Point = namedtuple('Point', ['x', 'y'], verbose=True)
    class Point(tuple):
        'Point(x, y)'
    
        __slots__ = ()
    
        _fields = ('x', 'y')
    
        def __new__(_cls, x, y):
            'Create a new instance of Point(x, y)'
            return _tuple.__new__(_cls, (x, y))      # Here. Why _tuple?
    

**Update**

One more question:

As @vaultah's answer, good job and thank you:D

But is there some advantage that `from builtins import property as _property,
tuple as _tuple`?

Is that just let `tuple` be a _protected value_? Am I right?


Answer: From the generic [source
code](http://hg.python.org/cpython/file/e831a98b3f43/Lib/collections/__init__.py#l266)
(you can see the source code generated for this specific namedtuple by
printing `Point._source`):

    
    
    from builtins import property as _property, tuple as _tuple
    

So `_tuple` here is just an alias for built-in `tuple`:

    
    
    In [1]: from builtins import tuple as _tuple
    
    In [2]: tuple is _tuple
    Out[2]: True
    

Namedtuple appeared in Python 2.6. The initial source for its `__new__` method
was

    
    
    def __new__(cls, %(argtxt)s):
        return tuple.__new__(cls, (%(argtxt)s)) \n
    

The thing is, the source code is in _string_. They later format it using `%
locals()`. If the `tuple` was listed in `argtxt`, the `tuple.__new__` would
have called `__new__` method on whatever the `tuple` field contained. `_tuple`
works as expected because `namedtuple` doesn't allow field names starting with
`_`.

The bug was fixed in Python 2.6.3 release (see the
[changelog](http://ftp.python.org/download/releases/2.6.3/NEWS.txt) \-
_collections.namedtuple() was not working with the following field names: cls,
self, tuple, itemgetter, and property._).

