Python: subclassing tuples and operators

oop, operators, python, subclass, tuples

Solution

The issue is in your `__new__` method is creating your objects. You're returning regular `tuple` instances, not instances of your subclass, so the `__eq__` method you've written will never be called.

Try changing `__new__` to:

def __new__(cls, data):
    self = super(OPS, cls).__new__(cls, data)
    return self

The `self` value returned by this version will be an `OPS` instance.

Problem

I am subclassing tuple. I want to override the equal method. It doesn't seem to be working. This is my minimum working example: ``` class OPS(tuple): def __new__(self, data): self=tuple(data) return self def __eq__(A,B): print 'Hi' return True O1=OPS([1,2,3]) O2=OPS([1,2,4]) O1==O2 ``` It returns `False`, when it should be printing `'Hi'` and then returning `True`. Any ideas on what I am doing wrong? I bet it is quite stupid, but I am at loss.

Original source