Skip to content

Commit 7087138

Browse files
committed
Add: Index.__repr_pretty__
1 parent a3287f1 commit 7087138

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

python/usearch/index.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,12 +1234,10 @@ def __repr__(self) -> str:
12341234
self.hardware_acceleration,
12351235
)
12361236

1237-
def _repr_pretty_(self, printer, cycle) -> str:
1237+
def __repr_pretty__(self) -> str:
12381238
if not hasattr(self, "_compiled"):
12391239
return "usearch.Index(failed)"
1240-
level_stats = [
1241-
f"--- {i}. {self.level_stats(i).nodes:,} nodes" for i in range(self.nlevels)
1242-
]
1240+
level_stats = [f"--- {i}. {self.level_stats(i).nodes:,} nodes" for i in range(self.nlevels)]
12431241
lines = "\n".join(
12441242
[
12451243
"usearch.Index",
@@ -1263,7 +1261,10 @@ def _repr_pretty_(self, printer, cycle) -> str:
12631261
*level_stats,
12641262
]
12651263
)
1266-
printer.text(lines)
1264+
return lines
1265+
1266+
def _repr_pretty_(self, printer, cycle):
1267+
printer.text(self.__repr_pretty__())
12671268

12681269

12691270
class Indexes:

0 commit comments

Comments
 (0)