We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ece2fe1 commit ce569deCopy full SHA for ce569de
fsspec/core.py
@@ -204,6 +204,12 @@ def __exit__(self, *args):
204
break
205
[s.__exit__(*args) for s in self]
206
207
+ def __getitem__(self, item):
208
+ out = super().__getitem__(item)
209
+ if isinstance(item, slice):
210
+ return OpenFiles(out, mode=self.mode, fs=self.fs)
211
+ return out
212
+
213
def __repr__(self):
214
return "<List of %s OpenFile instances>" % len(self)
215
fsspec/tests/test_core.py
@@ -184,6 +184,8 @@ def test_multi_context(tmpdir):
184
assert isinstance(files, OpenFiles)
185
assert isinstance(files[0], OpenFile)
186
assert len(files) == 2
187
+ assert isinstance(files[:1], OpenFiles)
188
+ assert len(files[:1]) == 1
189
with files as of:
190
assert len(of) == 2
191
assert not of[0].closed
0 commit comments