Raymond Hettinger added the comment:
> 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))
----------
resolution: -> invalid
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue21181>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com