Two NCubeInterior objects with the same name but different parametric bounds compare equal, but they have different hashes. This breaks Python's requirement that a == b implies hash(a) == hash(b).
Reproduced with SymPDE 0.20.0:
from sympde.topology import Square
P = Square('P', bounds1=(0, 1), bounds2=(0, 1)).interior
Q = Square('P', bounds1=(0, 2), bounds2=(0, 1)).interior
P.min_coords, P.max_coords # ((0.0, 0.0), (1.0, 1.0))
Q.min_coords, Q.max_coords # ((0.0, 0.0), (2.0, 1.0))
P == Q # True: equality ignores the bounds
hash(P) == hash(Q) # False: sets disagree with ==
P._hashable_content() returns only ('P',), so == compares names only, while the hash depends on other data as well.
Expected
Patches with different bounds compare unequal, and __eq__ and __hash__ agree. Including min_coords and max_coords in _hashable_content would probably fix both.
Context
In PSYDAC we need to check that a user-given domain matches the domain stored in a geometry file. Because of this bug we have to compare the bounds explicitly.
Two
NCubeInteriorobjects with the same name but different parametric bounds compare equal, but they have different hashes. This breaks Python's requirement thata == bimplieshash(a) == hash(b).Reproduced with SymPDE 0.20.0:
P._hashable_content()returns only('P',),so==compares names only, while the hash depends on other data as well.Expected
Patches with different bounds compare unequal, and
__eq__and__hash__agree. Includingmin_coordsandmax_coordsin_hashable_contentwould probably fix both.Context
In PSYDAC we need to check that a user-given domain matches the domain stored in a geometry file. Because of this bug we have to compare the bounds explicitly.