Skip to content

Commit

Permalink
add __eq__ implementation to allow deduping of graph reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
gtfierro committed Dec 6, 2023
1 parent ec71411 commit 867c2e8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions buildingmotif/dataclasses/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class GraphDiff:
validation_result: Graph
graph: Graph

def __eq__(self, other):
if not isinstance(other, GraphDiff):
return False
return self.reason() == other.reason()

def resolve(self, lib: "Library") -> List["Template"]:
"""Produces a list of templates to resolve this GraphDiff.
Expand Down Expand Up @@ -82,7 +87,7 @@ def __hash__(self):
return hash(self.reason())


@dataclass(frozen=True)
@dataclass(frozen=True, eq=False)
class PathClassCount(GraphDiff):
"""Represents an entity missing paths to objects of a given type:
$this <path> <object> .
Expand Down Expand Up @@ -116,7 +121,7 @@ def resolve(self, lib: "Library") -> List["Template"]:
return [lib.create_template(f"resolve_{token_hex(4)}", body)]


@dataclass(frozen=True, unsafe_hash=True)
@dataclass(frozen=True, unsafe_hash=True, eq=False)
class PathShapeCount(GraphDiff):
"""Represents an entity missing paths to objects that match a given shape.
$this <path> <object> .
Expand Down Expand Up @@ -163,7 +168,7 @@ def resolve(self, lib: "Library") -> List["Template"]:
return generated


@dataclass(frozen=True)
@dataclass(frozen=True, eq=False)
class RequiredPath(GraphDiff):
"""Represents an entity missing a required property."""

Expand Down Expand Up @@ -192,7 +197,7 @@ def resolve(self, lib: "Library") -> List["Template"]:
return [lib.create_template(f"resolve{token_hex(4)}", body)]


@dataclass(frozen=True)
@dataclass(frozen=True, eq=False)
class RequiredClass(GraphDiff):
"""Represents an entity that should be an instance of the class."""

Expand All @@ -216,7 +221,7 @@ def resolve(self, lib: "Library") -> List["Template"]:
return [lib.create_template(f"resolve{token_hex(4)}", body)]


@dataclass(frozen=True)
@dataclass(frozen=True, eq=False)
class GraphClassCardinality(GraphDiff):
"""Represents a graph that is missing an expected number of instances of
the given class.
Expand Down

0 comments on commit 867c2e8

Please sign in to comment.