hdl.ast: do not cast comparand to shape in Shape.__eq__.

This doesn't match how other Python comparison operators work.
E.g. `1 == int("1")` but `1 != "1"`.
This commit is contained in:
Catherine 2023-02-28 15:52:50 +00:00
parent 35561ea11a
commit 14e73a73de
4 changed files with 10 additions and 21 deletions

View file

@ -133,13 +133,8 @@ class Shape:
return "unsigned({})".format(self.width)
def __eq__(self, other):
if not isinstance(other, Shape):
try:
other = self.__class__.cast(other)
except TypeError as e:
raise TypeError("Shapes may be compared with shape-castable objects, not {!r}"
.format(other)) from e
return self.width == other.width and self.signed == other.signed
return (isinstance(other, Shape) and
self.width == other.width and self.signed == other.signed)
def unsigned(width):

View file

@ -38,7 +38,8 @@ class Field:
def __eq__(self, other):
return (isinstance(other, Field) and
self._shape == other.shape and self._offset == other.offset)
Shape.cast(self._shape) == Shape.cast(other.shape) and
self._offset == other.offset)
def __repr__(self):
return f"Field({self._shape!r}, {self._offset})"