Vedran Čačić added the comment:

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.")

----------
nosy: +Vedran.Čačić

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24931>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to