move equals attr test to equals attr folder

This commit is contained in:
Joe Farebrother
2025-07-09 15:25:21 +01:00
parent a687b60af9
commit 8fb9bdd0af
4 changed files with 1 additions and 2 deletions

View File

@@ -0,0 +1 @@
| attr_eq_test.py:21:1:21:27 | class BadColorPoint | The class 'BadColorPoint' does not override $@, but adds the new attribute $@. | attr_eq_test.py:10:5:10:28 | Function Point.__eq__ | '__eq__' | attr_eq_test.py:25:9:25:19 | Attribute | _color |

View File

@@ -0,0 +1,107 @@
class Point(object):
def __init__(self, x, y):
self._x = x
self._y = y
def __repr__(self):
return 'Point(%r, %r)' % (self._x, self._y)
def __eq__(self, other):
if not isinstance(other, Point):
return False
return self._x == other._x and self._y == other._y
def __ne__(self, other):
return not self.__eq__(other)
def __hash__(self):
return hash((self._x, self._y))
class BadColorPoint(Point):
def __init__(self, x, y, color):
Point.__init__(self, x, y)
self._color = color
def __repr__(self):
return 'ColorPoint(%r, %r)' % (self._x, self._y, self._color)
class GoodColorPoint(Point):
def __init__(self, x, y, color):
Point.__init__(self, x, y)
self._color = color
def __repr__(self):
return 'ColorPoint(%r, %r)' % (self._x, self._y, self._color)
def __eq__(self, other):
if not isinstance(other, GoodColorPoint):
return False
return Point.__eq__(self, other) and self._color == other._color
def __ne__(self, other):
return not self.__eq__(other)
def __hash__(self):
return hash((self._x, self._y, self._color))
class GenericPoint(object):
def __init__(self, x, y):
self._x = x
self._y = y
def __repr__(self):
return 'Point(%r, %r)' % (self._x, self._y)
def __eq__(self, other):
return self.__class__ == other.__class__ and self.__dict__ == other.__dict__
def __ne__(self, other):
return not self.__eq__(other)
def __hash__(self):
return hash((self._x, self._y))
class GoodGenericColorPoint(GenericPoint):
def __init__(self, x, y, color):
GenericPoint.__init__(self, x, y)
self._color = color
class RedefineEq(object):
def __init__(self, x, y):
self._x = x
self._y = y
def __eq__(self, other):
return self is other
class OK1(RedefineEq):
def __init__(self, x, y, z):
RedefineEq.__init__(self, x, y)
self.z = z
class OK2(GenericPoint):
def __init__(self, x, y, color):
GenericPoint.__init__(self, x, y)
self._color = color
def __eq__(self, other):
return self is other
class ExpectingAttribute(object):
def __eq__(self, other):
return self.x == other.x
class OK3(ExpectingAttribute):
def __init__(self):
self.x = 4