Skip to content

Commit

Permalink
Simplify graph getters
Browse files Browse the repository at this point in the history
* Calls like `get_node_defaults()` and `get_strict()` took an extra
  second argument that was never used for anything — eliminate it.

* The `get_*_defaults()` methods also wasted time checking
  whether the return value of `get_node()` is a list, but it's
  always a list.
  • Loading branch information
ferdnyc committed Dec 6, 2024
1 parent 0937a60 commit cdb9037
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions src/pydot/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,13 +1001,9 @@ def get_graph_type(self) -> Optional[str]:
def set_graph_defaults(self, **attrs: Any) -> None:
self.add_node(Node("graph", **attrs))

def get_graph_defaults(self, **attrs: Any) -> Any:
def get_graph_defaults(self) -> Any:
graph_nodes = self.get_node("graph")

if isinstance(graph_nodes, (list, tuple)):
return [node.get_attributes() for node in graph_nodes]

return graph_nodes.get_attributes()
return [node.get_attributes() for node in graph_nodes]

def set_node_defaults(self, **attrs: Any) -> None:
"""Define default node attributes.
Expand All @@ -1017,24 +1013,16 @@ def set_node_defaults(self, **attrs: Any) -> None:
"""
self.add_node(Node("node", **attrs))

def get_node_defaults(self, **attrs: Any) -> Any:
def get_node_defaults(self) -> Any:
graph_nodes = self.get_node("node")

if isinstance(graph_nodes, (list, tuple)):
return [node.get_attributes() for node in graph_nodes]

return graph_nodes.get_attributes()
return [node.get_attributes() for node in graph_nodes]

def set_edge_defaults(self, **attrs: Any) -> None:
self.add_node(Node("edge", **attrs))

def get_edge_defaults(self, **attrs: Any) -> Any:
def get_edge_defaults(self) -> Any:
graph_nodes = self.get_node("edge")

if isinstance(graph_nodes, (list, tuple)):
return [node.get_attributes() for node in graph_nodes]

return graph_nodes.get_attributes()
return [node.get_attributes() for node in graph_nodes]

def set_simplify(self, simplify: bool) -> None:
"""Set whether to simplify or not.
Expand Down Expand Up @@ -1075,7 +1063,7 @@ def set_strict(self, val: bool) -> None:
"""
self.obj_dict["strict"] = val

def get_strict(self, val: Any) -> Optional[bool]:
def get_strict(self) -> Optional[bool]:
"""Get graph's 'strict' mode (True, False).
This option is only valid for top level graphs.
Expand All @@ -1093,7 +1081,7 @@ def set_suppress_disconnected(self, val: str) -> None:
"""
self.obj_dict["suppress_disconnected"] = val

def get_suppress_disconnected(self, val: Any) -> Optional[bool]:
def get_suppress_disconnected(self) -> Optional[bool]:
"""Get if suppress disconnected is set.
Refer to set_suppress_disconnected for more information.
Expand Down

0 comments on commit cdb9037

Please sign in to comment.