Skip to content

Commit 267b28c

Browse files
committed
Add repr for lambda transforms.
1 parent 9115fdf commit 267b28c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/trecs/data/util.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,16 @@ def map(self, element): # pyright: ignore[reportIncompatibleMethodOverride]
290290
return [self.func(x, *self.args, **self.kwargs) for x in element]
291291

292292

293-
class LambdaRandomMap(grain.transforms.RandomMap, Generic[T, U]):
293+
class LambdaReprMixin:
294+
func: Callable
295+
296+
def __repr__(self) -> str:
297+
_id = id(self)
298+
name = self.__class__.__name__
299+
return f"<{name} at 0x{_id:x}: {self.func.__name__}>"
300+
301+
302+
class LambdaRandomMap(grain.transforms.RandomMap, LambdaReprMixin, Generic[T, U]):
294303
"""Apply a callable to all elements of a map, receiving a random number generator."""
295304

296305
def __init__(
@@ -306,7 +315,7 @@ def random_map( # pyright: ignore[reportIncompatibleMethodOverride]
306315
return self.func(element, rng, *self.args, **self.kwargs)
307316

308317

309-
class LambdaMap(grain.transforms.Map, Generic[T, U]):
318+
class LambdaMap(grain.transforms.Map, LambdaReprMixin, Generic[T, U]):
310319
"""Apply a callable to all elements of a map."""
311320

312321
def __init__(

0 commit comments

Comments
 (0)