When I try to override the magic method __eq__
, and use super
to access the base method found in object
, I get an error. There's no way this is a bug, but it sure feels like one:
class A(object):
def __eq__(self, other):
return super(A, self).__eq__(other)
A() == 0
# raises AttributeError: 'super' object has no attribute '__eq__'
This is unintuitive because object.__eq__
exists, but for class A(object): pass
it doesn't. If I'm not mistaken __eq__
resorts to an is
check, so that may be the workaround here, but using is
instead of super
isn't mixin friendly. Going that route is ok in my case, but in others it might not be.
Any suggestions, or info on why __eq__
works this way would be great.
object
does not support__eq__
on instances ... tryobject().__eq__
, it will raise anAttributeError
... insteadobject.__eq__ is (probably) a classmethod for checking if types are identical (eg
object.__eq__(object)`) – Haldemanother
; it will compare a newly-created "blank" object withother
. – Orthorhombicobject().__eq__
doesn't even work, it will raise an attribute error (edited to make it clear) – Haldeman