Skip to content

Commit

Permalink
Remove unneeded json encoder.
Browse files Browse the repository at this point in the history
  • Loading branch information
theotherbjorn committed Jan 1, 2025
1 parent d68d449 commit 1023a59
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions pydeps/depgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,6 @@ def __hash__(self):
def __eq__(self, other):
return self.src.name == other.src.name

def __json__(self):
return self.src.name


class GraphNodeEncoder(json.JSONEncoder):
def default(self, obj):
if hasattr(obj, '__json__'):
return obj.__json__()
if isinstance(obj, GraphNode):
return obj.name
return super().default(obj)


class Graph:
def __init__(self, vertices: list[GraphNode], edges: list[tuple[GraphNode, GraphNode]]):
Expand All @@ -208,11 +196,11 @@ def __init__(self, vertices: list[GraphNode], edges: list[tuple[GraphNode, Graph
def __json__(self):
return {
"edges": [(u, v) for u, v in self.edges],
"neighbours": {u.__json__(): [v.__json__() for v in self.neighbours[u]] for u in self.V}
"neighbours": {u.src.name: [v.src.name for v in self.neighbours[u]] for u in self.V}
}

def __str__(self):
return json.dumps(self, indent=4, cls=GraphNodeEncoder)
return json.dumps(self, indent=4)

def transpose(self):
return Graph(self.V, [(v, u) for u, v in self.edges])
Expand Down

0 comments on commit 1023a59

Please sign in to comment.