gh-153037: Make ZstdFile.__next__ raise io.UnsupportedOperation on non-readable files (GH-153045)
Make `ZstdFile.__next__` raise `io.UnsupportedOperation` on non-readable files, consistent with other compression modules.
(cherry picked from commit
ed716551e13d1e46a5cd17955657d64b8824626a)
Co-authored-by: Ćukasz <lukaszlapinski7@gmail.com>
return self._buffer.peek(size)
def __next__(self):
+ self._check_can_read()
if ret := self._buffer.readline():
return ret
raise StopIteration
f.read(100)
with self.assertRaises(io.UnsupportedOperation):
f.seek(100)
+ with self.assertRaises(io.UnsupportedOperation):
+ next(iter(f))
self.assertEqual(f.closed, True)
with self.assertRaises(ValueError):
f.readable()
--- /dev/null
+Fix :class:`~compression.zstd.ZstdFile` raising :exc:`AttributeError`
+instead of :exc:`io.UnsupportedOperation` when iterating over a file that
+is not open for reading.