This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients Jim.Peterson, rhettinger
Date 2014-04-09.00:55:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1397004922.05.0.60843731715.issue21181@psf.upfronthosting.co.za>
In-reply-to
Content
> whatever compelled the developer to declare the named fields 
> using _property seems to be ignored in the definition of __dict__.

What compelled the _property alias is that the user could name an attribute "property" which would cause a conflict if _property has not been renamed.  

For example:

   T = namedtuple('T', ['property', 'plant', 'equipment'])

would create the following field definitions:

    property = _property(_itemgetter(0), doc='Alias for field number 0')

    plant = _property(_itemgetter(1), doc='Alias for field number 1')

    equipment = _property(_itemgetter(2), doc='Alias for field number 2')

Note, if we didn't use _property, the builtin property() would be shadowed.

The code for __dict__ occurs upstream (before the field definitions), so it is safe from redefinition:

    @property
    def __dict__(self):
        'A new OrderedDict mapping field names to their values'
        return OrderedDict(zip(self._fields, self))
History
Date User Action Args
2014-04-09 00:55:22rhettingersetrecipients: + rhettinger, Jim.Peterson
2014-04-09 00:55:22rhettingersetmessageid: <1397004922.05.0.60843731715.issue21181@psf.upfronthosting.co.za>
2014-04-09 00:55:22rhettingerlinkissue21181 messages
2014-04-09 00:55:20rhettingercreate