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 Samuel Isaacson, rhettinger
Date 2015-08-25.02:54:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1440471272.88.0.197023135588.issue24931@psf.upfronthosting.co.za>
In-reply-to
Content
For __dict__, I'm not sure what the right behavior should by for subclasses that don't define __slots__.  In Python 3, the __dict__ is returning the dict for the subclass.  This might be the correct and most desirable behavior:

    >>> class Point(namedtuple('_Point', ['x', 'y'])):
            pass
    >>> a = Point(3, 4)
    >>> a.w = 5
    >>> a.__dict__
    {'w': 5}

If we leave the __dict__ behavior as is in Py3, then we still need to get _asdict() back to its documented behavior.  For that, we would need to disconnect it from __dict__ by restoring the Py2.7 code for _asdict():

    def _asdict(self):
        'Return a new OrderedDict which maps field names to their values'
        return OrderedDict(zip(self._fields, self))

All this needs to be thought-out carefully.  Putting in __dict__ support originally looked like a bugfix to get vars() working correctly, but it caused problems with pickling which then led to the addition of __getnewargs__.  It seems that defining __dict__ leads to problems no matter how you do it.

My inclination is to remove __dict__ and __getewargs__ from the namedtuple definition entirely and return to a simpler state of affairs that is easier to reason about and less likely to lead to unexpected behaviors like the one in this bug report.

One note:  using the Py2.7 namedtuple code in Python3 still doesn't restore the old behavior.  Something else in the language appears to have changed (causing the subclasses' __dict__ to take precedence over the inherited __dict__ property).
History
Date User Action Args
2015-08-25 02:54:32rhettingersetrecipients: + rhettinger, Samuel Isaacson
2015-08-25 02:54:32rhettingersetmessageid: <1440471272.88.0.197023135588.issue24931@psf.upfronthosting.co.za>
2015-08-25 02:54:32rhettingerlinkissue24931 messages
2015-08-25 02:54:32rhettingercreate