I have a tiny class that extends a namedtuple
, but the __dict__
property of its instances is always returning empty.
Point = namedtuple('Point', 'x y')
p1 = Point(20, 15)
print(p1, p1.__dict__)
# Point(x=20, y=15) OrderedDict([('x', 20), ('y', 15)]) <--- ok
class SubPoint(Point): pass
p2 = SubPoint(20, 15)
print(p2, p2.__dict__)
# SubPoint(x=20, y=15) {} <--- why is it empty?
p2
has the attributes, but its __dict__
is empty. They are listed correctly with dir()
, though, which is strange. Note this work correctly when SubPoint
extends a vanilla class.
What is happening, and how do I list the attributes in my subclass instance?