core: Fix some private member accesses (#30912)

See https://github.com/langchain-ai/langchain/pull/30666

---------

Co-authored-by: Eugene Yurtsev <eugene@langchain.dev>
This commit is contained in:
Christophe Bornet 2025-05-12 19:42:26 +02:00 committed by GitHub
parent 1e56c66f86
commit 83d006190d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -163,16 +163,21 @@ class AsciiCanvas:
self.point(x0 + width, y0 + height, "+") self.point(x0 + width, y0 + height, "+")
class _EdgeViewer:
def __init__(self) -> None:
self.pts: list[tuple[float]] = []
def setpath(self, pts: list[tuple[float]]) -> None:
self.pts = pts
def _build_sugiyama_layout( def _build_sugiyama_layout(
vertices: Mapping[str, str], edges: Sequence[LangEdge] vertices: Mapping[str, str], edges: Sequence[LangEdge]
) -> Any: ) -> Any:
try: try:
from grandalf.graphs import Edge, Graph, Vertex # type: ignore[import-untyped] from grandalf.graphs import Edge, Graph, Vertex # type: ignore[import-untyped]
from grandalf.layouts import SugiyamaLayout # type: ignore[import-untyped] from grandalf.layouts import SugiyamaLayout # type: ignore[import-untyped]
from grandalf.routing import ( # type: ignore[import-untyped] from grandalf.routing import route_with_lines # type: ignore[import-untyped]
EdgeViewer,
route_with_lines,
)
except ImportError as exc: except ImportError as exc:
msg = "Install grandalf to draw graphs: `pip install grandalf`." msg = "Install grandalf to draw graphs: `pip install grandalf`."
raise ImportError(msg) from exc raise ImportError(msg) from exc
@ -199,7 +204,7 @@ def _build_sugiyama_layout(
minw = min(v.view.w for v in vertices_list) minw = min(v.view.w for v in vertices_list)
for edge in edges_: for edge in edges_:
edge.view = EdgeViewer() edge.view = _EdgeViewer()
sug = SugiyamaLayout(graph.C[0]) sug = SugiyamaLayout(graph.C[0])
graph = graph.C[0] graph = graph.C[0]
@ -277,7 +282,7 @@ def draw_ascii(vertices: Mapping[str, str], edges: Sequence[LangEdge]) -> str:
ylist.extend((vertex.view.xy[1], vertex.view.xy[1] + vertex.view.h)) ylist.extend((vertex.view.xy[1], vertex.view.xy[1] + vertex.view.h))
for edge in sug.g.sE: for edge in sug.g.sE:
for x, y in edge.view._pts: for x, y in edge.view.pts:
xlist.append(x) xlist.append(x)
ylist.append(y) ylist.append(y)
@ -293,12 +298,12 @@ def draw_ascii(vertices: Mapping[str, str], edges: Sequence[LangEdge]) -> str:
# NOTE: first draw edges so that node boxes could overwrite them # NOTE: first draw edges so that node boxes could overwrite them
for edge in sug.g.sE: for edge in sug.g.sE:
if len(edge.view._pts) <= 1: if len(edge.view.pts) <= 1:
msg = "Not enough points to draw an edge" msg = "Not enough points to draw an edge"
raise ValueError(msg) raise ValueError(msg)
for index in range(1, len(edge.view._pts)): for index in range(1, len(edge.view.pts)):
start = edge.view._pts[index - 1] start = edge.view.pts[index - 1]
end = edge.view._pts[index] end = edge.view.pts[index]
start_x = int(round(start[0] - minx)) start_x = int(round(start[0] - minx))
start_y = int(round(start[1] - miny)) start_y = int(round(start[1] - miny))