nodes: add helper function to retrieve the pretty-printed node as a string

This commit is contained in:
Antoine Viallon 2024-07-26 00:11:38 +02:00
parent e28b1ef802
commit 89a9bb7901
Signed by: aviallon
GPG key ID: 186FC35EDEB25716

View file

@ -45,7 +45,10 @@ class Node:
return f"{self.__class__.__name__}({vals})" return f"{self.__class__.__name__}({vals})"
def pprint(self, depth: int | None = None, indent: str = "\t"): def pprint(self, depth: int | None = None, indent: str = "\t"):
print("\n".join(self._pprint(depth=depth, indent=indent))) print(self._pretty(depth, indent))
def _pretty(self, depth: int | None = None, indent: str = "\t") -> str:
return "\n".join(self._pprint(depth=depth, indent=indent))
def _pprint(self, depth: int | None, indent: str, _depth: int = 0) -> list[str]: def _pprint(self, depth: int | None, indent: str, _depth: int = 0) -> list[str]:
if depth is not None and _depth >= depth: if depth is not None and _depth >= depth: