Skip to content

Commit eee76b3

Browse files
committed
Improve readability
1 parent 09ffa9e commit eee76b3

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

torchdata/datapipes/iter/util/converter.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,18 @@ def __getitem__(self, index):
8686
if self._map is None:
8787
self._map = {}
8888
self._itr = iter(self.datapipe)
89-
raise KeyError
90-
return self._map[index]
89+
else:
90+
return self._map[index]
9191
except KeyError:
92-
while not self._depleted:
93-
try:
94-
key, value = self._load_next_item()
95-
if key == index:
96-
return value
97-
except StopIteration:
98-
self._depleted = True
99-
raise IndexError(f"Index {index} is invalid for IterToMapConverter.")
92+
pass
93+
while not self._depleted:
94+
try:
95+
key, value = self._load_next_item()
96+
if key == index:
97+
return value
98+
except StopIteration:
99+
self._depleted = True
100+
raise IndexError(f"Index {index} is invalid for IterToMapConverter.")
100101

101102
def _load_next_item(self):
102103
elem = next(self._itr)

0 commit comments

Comments
 (0)