@@ -323,15 +323,38 @@ def __str__(self) -> str:
323323 >>> g.add_edge(v2, v3)
324324 >>> str(g)
325325
326- :seealso: :meth:`show`
326+ :seealso: :meth:`__repr__` :meth:` show`
327327 """
328328 s = f"{ self .__class__ .__name__ } : { self .n :,} { 'vertex' if self .n == 1 else 'vertices' } , { self .ne :,} edge{ 's' [:self .ne ^ 1 ]} , { self .nc :,} component{ 's' [:self .nc ^ 1 ]} "
329329 return s
330330
331331 def __repr__ (self ) -> str :
332- # NOTE: this is shadowed by the __repr__ defined further below in
333- # this class, which is the one actually used -- kept as-is here to
334- # avoid changing behaviour as part of a typing-only pass.
332+ """
333+ Representation of the graph, the same one-line summary as :meth:`__str__`
334+
335+ :return: one-line summary of vertex/edge/component counts
336+ :rtype: str
337+
338+ The representation of a graph does not list its vertices, since that
339+ would be as long as the graph, and a ``repr`` is what appears in a
340+ notebook cell, a debugger, a log or an error message. Use
341+ :meth:`show` to list them.
342+
343+ .. runblock:: pycon
344+
345+ >>> from pgraph import UGraph
346+ >>> g = UGraph()
347+ >>> v1 = g.add_vertex(coord=[0,0], name='v1')
348+ >>> v2 = g.add_vertex(coord=[1,1], name='v2')
349+ >>> g.add_edge(v1, v2)
350+ >>> repr(g)
351+
352+ .. versionchanged:: 1.1
353+ Was one line per vertex, with its name, coordinate and component;
354+ that is now printed by :meth:`show`.
355+
356+ :seealso: :meth:`__str__` :meth:`show`
357+ """
335358 return str (self )
336359
337360 @classmethod
@@ -1501,7 +1524,11 @@ def remove(self, x: Edge | Vertex) -> None:
15011524
15021525 def show (self ) -> None :
15031526 """
1504- Print a summary of all vertices and edges to stdout
1527+ Print a listing of all vertices and edges to stdout
1528+
1529+ Each vertex is shown with its name, coordinate and component number,
1530+ and each edge by its endpoints, cost and data. This is as long as the
1531+ graph, unlike :meth:`__str__` and :meth:`__repr__`, which are one line.
15051532
15061533 .. runblock:: pycon
15071534
@@ -1512,11 +1539,18 @@ def show(self) -> None:
15121539 >>> g.add_edge(v1, v2)
15131540 >>> g.show()
15141541
1515- :seealso: :meth:`__str__`
1542+ .. versionchanged:: 1.1
1543+ Each vertex is shown with its coordinate and component number,
1544+ which were what ``repr(g)`` listed before it became one line.
1545+
1546+ :seealso: :meth:`__str__` :meth:`plot`
15161547 """
15171548 print ("vertices:" )
15181549 for v in self ._vertexlist :
1519- print (" " + str (v ))
1550+ line = f" { v .name } at { v .coord } "
1551+ if v .label is not None :
1552+ line += f" component={ v .label } "
1553+ print (line )
15201554 print ("edges:" )
15211555 for e in self ._edges :
15221556 print (" " + str (e ))
@@ -1808,33 +1842,6 @@ def heuristic(self, heuristic: Callable[[NDArray], float] | str) -> None:
18081842 """
18091843 self ._heuristic = self ._metricfunc (heuristic )
18101844
1811- def __repr__ (self ) -> str : # type: ignore[no-redef]
1812- """
1813- Detailed representation of the graph, one line per vertex
1814-
1815- :return: one line per vertex showing its name, coordinate and component
1816- :rtype: str
1817-
1818- .. runblock:: pycon
1819-
1820- >>> from pgraph import UGraph
1821- >>> g = UGraph()
1822- >>> v1 = g.add_vertex(coord=[0,0], name='v1')
1823- >>> v2 = g.add_vertex(coord=[1,1], name='v2')
1824- >>> v3 = g.add_vertex(coord=[2,2], name='v3')
1825- >>> g.add_edge(v1, v2)
1826- >>> g.add_edge(v2, v3)
1827- >>> repr(g)
1828-
1829- """
1830- s = [f"{ self .__class__ .__name__ } :" ]
1831- for vertex in self :
1832- ss = f" { vertex .name } at { vertex .coord } "
1833- if vertex .label is not None :
1834- ss += f" component={ vertex .label } "
1835- s .append (ss )
1836- return "\n " .join (s )
1837-
18381845 def __getitem__ (self , i : int | str | Vertex ) -> Vertex :
18391846 """
18401847 Get vertex (base class method)
@@ -2528,7 +2535,7 @@ def plot(
25282535 ... g.add_edge(a, b);
25292536 >>> g.plot(block=None)
25302537
2531- :seealso: :meth:`highlight_path` :meth:`highlight_edge`
2538+ :seealso: :meth:`highlight_path` :meth:`highlight_edge` :meth:`show`
25322539 """
25332540 import matplotlib .pyplot as plt
25342541 from matplotlib .patches import FancyArrowPatch
0 commit comments