Skip to content

Commit

Permalink
topology.py -> update GroupBy.__str__ __repr__ and add _repr_pretty_
Browse files Browse the repository at this point in the history
  • Loading branch information
jdegenstein authored Feb 21, 2024
1 parent c8d9906 commit 38255f4
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/build123d/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
from typing_extensions import Self, Literal

from anytree import NodeMixin, PreOrderIter, RenderTree
from IPython.lib.pretty import pretty
from scipy.spatial import ConvexHull
from vtkmodules.vtkCommonDataModel import vtkPolyData
from vtkmodules.vtkFiltersCore import vtkPolyDataNormals, vtkTriangleFilter
Expand Down Expand Up @@ -3751,13 +3752,21 @@ def __getitem__(self, key: int):
return self.groups[key]

def __str__(self):
body = ",\n".join(str(x) for x in self)
return "[" + body + "]"

return pretty(self)

def __repr__(self):
# TODO:replace in the future with a version using
# implied line continuations
return self.__str__()
return repr(ShapeList(self))

def _repr_pretty_(self, p, cycle = False):
if cycle:
p.text('(...)')
else:
with p.group(1, '[', ']'):
for idx, item in enumerate(self):
if idx:
p.text(',')
p.breakable()
p.pretty(item)

def group(self, key: K):
"""Select group by key"""
Expand Down

0 comments on commit 38255f4

Please sign in to comment.