Did something about `namedtuple` change in 3.5.1?
Per Python bug #24931:
[
__dict__
] disappeared because it was fundamentally broken in Python 3, so it had to be removed. Providing__dict__
broke subclassing and produced odd behaviors.
Revision that made the change
Specifically, subclasses without __slots__
defined would behave weirdly:
>>> Cluster = namedtuple('Cluster', 'x y')
>>> class Cluster2(Cluster):
pass
>>> vars(Cluster(1,2))
OrderedDict([('x', 1), ('y', 2)])
>>> vars(Cluster2(1,2))
{}
Use ._asdict()
.
From the docs
Named tuple instances do not have per-instance dictionaries, so they are lightweight and require no more memory than regular tuples.
The docs (and help(namedtuple)
) say to use c._asdict()
to convert to a dict.