Replace str by repr for DataChunk (#63184)
authorErjia Guan <erjia@fb.com>
Mon, 16 Aug 2021 13:39:56 +0000 (06:39 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Mon, 16 Aug 2021 13:41:38 +0000 (06:41 -0700)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/63184

Test Plan: Imported from OSS

Reviewed By: bdhirsh

Differential Revision: D30288892

Pulled By: ejguan

fbshipit-source-id: 45c88fdd3987e234f2c22ebbbfd8d5044983c34c

test/test_datapipe.py
torch/utils/data/dataset.py

index 6454263..80fe758 100644 (file)
@@ -73,7 +73,7 @@ except ImportError:
     HAS_DILL = False
 skipIfNoDill = skipIf(not HAS_DILL, "no dill")
 
-T_co = TypeVar('T_co', covariant=True)
+T_co = TypeVar("T_co", covariant=True)
 
 
 def create_temp_dir_and_files():
@@ -110,15 +110,17 @@ def create_temp_dir_and_files():
 
 
 class TestDataChunk(TestCase):
-
     def test_as_string(self):
         elements = list(range(10))
-        chunk : DataChunk[int] = DataChunk(elements)
-        self.assertEquals(str(chunk), str(elements))
+        chunk: DataChunk[int] = DataChunk(elements)
+        self.assertEqual(str(chunk), str(elements))
 
+        batch = [elements] * 3
+        chunks: List[DataChunk] = [DataChunk(elements)] * 3
+        self.assertEqual(str(chunk), str(elements))
 
-class TestIterableDataPipeBasic(TestCase):
 
+class TestIterableDataPipeBasic(TestCase):
     def setUp(self):
         ret = create_temp_dir_and_files()
         self.temp_dir = ret[0][0]
index 6ee3d29..5b8102c 100644 (file)
@@ -39,7 +39,7 @@ class DataChunk(List[T]):
         res = indent + "[" + ", ".join([str(i) for i in iter(self)]) + "]"
         return res
 
-    def __str__(self):
+    def __repr__(self):
         return self.as_str()
 
     def __iter__(self) -> Iterator[T]: