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 veky
Recipients Samuel Isaacson, doko, eric.snow, larry, nchammas, python-dev, rhettinger, veky
Date 2015-12-25.15:56:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1451058987.25.0.865373080981.issue24931@psf.upfronthosting.co.za>
In-reply-to
Content
I agree that namedtuples having __dict__ is probably more trouble than benefit. But in my view, that's no reason for _asdict to not work correctly. The whole point of separate function (even going through the pain of underscore-starting public API, since everything else is even bigger pain) is that we sidestep the question of vars() and other standard Python hooks, and provide our way of extracting a namedtuple's namespace, for ones who need it.

Of course, the fix/workaround is trivial, as Raymond says: just

    def _asdict(self):
        return collections.OrderedDict(zip(self._fields, self))

That way, it doesn't matter whether self has a `__dict__` or not.

If you think it shouldn't be done, the documentation really needs to be changed. Current wording is very misleading, showing that `_asdict` works on a class having `__slots__ = ()`, but containing no explanation of that attribute being _necessary_ for `_asdict` to work. (It just says "This helps keep memory requirements low by preventing the creation of instance dictionaries.")
History
Date User Action Args
2015-12-25 15:56:27vekysetrecipients: + veky, rhettinger, doko, larry, python-dev, eric.snow, nchammas, Samuel Isaacson
2015-12-25 15:56:27vekysetmessageid: <1451058987.25.0.865373080981.issue24931@psf.upfronthosting.co.za>
2015-12-25 15:56:27vekylinkissue24931 messages
2015-12-25 15:56:26vekycreate