Skip to content

Commit 094a9c0

Browse files
committed
Prevent errors in __exit__ method due to improper __init__
1 parent a9e9aab commit 094a9c0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/zlib_ng/gzip_ng_threaded.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ def __init__(self,
204204
queue_size: int = 1,
205205
block_size: int = 1024 * 1024,
206206
):
207+
# File should be closed during init, so __exit__ method does not
208+
# touch the self.raw value before it is initialized.
209+
self._closed = True
207210
if "t" in mode or "r" in mode:
208211
raise ValueError("Only binary writing is supported")
209212
if "b" not in mode:
@@ -243,8 +246,8 @@ def __init__(self,
243246
self._crc = 0
244247
self.running = False
245248
self._size = 0
246-
self._closed = False
247249
self.raw = open_as_binary_stream(filename, mode)
250+
self._closed = False
248251
self._write_gzip_header()
249252
self.start()
250253

0 commit comments

Comments
 (0)