Skip to content

Commit 52d0ae1

Browse files
marcenacpThe TensorFlow Datasets Authors
authored andcommitted
Add an explicit repr to PythonDataSource.
Fixes: #5634 PiperOrigin-RevId: 690935467
1 parent c269b52 commit 52d0ae1

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

tensorflow_datasets/core/data_sources/python.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from typing import Any, Callable
2323

2424

25-
@dataclasses.dataclass
25+
@dataclasses.dataclass(repr=False)
2626
class PythonDataSource(MappingView, Sequence):
2727
"""Python data source backed by Python objects: length and __getitem__."""
2828

@@ -41,3 +41,6 @@ def __iter__(self):
4141

4242
def __getitem__(self, i: int) -> Any:
4343
return self.getitem(i)
44+
45+
def __repr__(self) -> str:
46+
return f'PythonDataSource(length={self.length})'

tensorflow_datasets/core/data_sources/python_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,8 @@ def test_tree_map_structure():
5454
tree.map_structure(func, source)
5555
calls = [mock.call(0), mock.call(1), mock.call(2)]
5656
func.assert_has_calls(calls)
57+
58+
59+
def test_repr():
60+
source = python.PythonDataSource(length=3, getitem=getitem)
61+
assert repr(source) == 'PythonDataSource(length=3)'

0 commit comments

Comments
 (0)