First para: I think maybe you're confusing 'class' with inheritance from 'object'. A good tip is to do:
class Foo(namedtuple('Foo', (...)):
def __repr__(self):
...
Your 'Foo' gets ordering, hashing, comparison, because it derives from 'namedtuple'. It gets '__repr__' too, but in the example I'm overriding that.
Re:Python Lists vs. Tuples
by throwaway274739 on Saturday August 20, 2016 @05:58AM
(#12325903)
I would also add
__slots__ = ()
to your class definition so that instances of Foo keep the small memory footprint benefits do namedtuple.
that said, writing generic code that works transparently with both namedtuple values and objects can be a bit irritating: e.g. you might want to derive a new value/object from an existing value/object that updates one of the attributes of the value/object.