55as functions for compressing and decompressing a :doc:`uproot.source.chunk.Chunk`.
66"""
77
8+ from __future__ import annotations
89
910import struct
1011import threading
@@ -88,7 +89,7 @@ class _DecompressZLIB:
8889 _2byte = b"ZL"
8990 _method = b"\x08 "
9091
91- def decompress (self , data , uncompressed_bytes = None ):
92+ def decompress (self , data : bytes , uncompressed_bytes = None ) -> bytes :
9293 import zlib
9394
9495 return zlib .decompress (data )
@@ -125,7 +126,7 @@ def level(self, value):
125126 raise ValueError ("Compression level must be between 0 and 9 (inclusive)" )
126127 self ._level = int (value )
127128
128- def compress (self , data ) :
129+ def compress (self , data : bytes ) -> bytes :
129130 import zlib
130131
131132 return zlib .compress (data , self ._level )
@@ -136,8 +137,9 @@ class _DecompressLZMA:
136137 _2byte = b"XZ"
137138 _method = b"\x00 "
138139
139- def decompress (self , data , uncompressed_bytes = None ):
140- lzma = uproot .extras .lzma ()
140+ def decompress (self , data : bytes , uncompressed_bytes = None ) -> bytes :
141+ import lzma
142+
141143 return lzma .decompress (data )
142144
143145
@@ -150,8 +152,6 @@ class LZMA(Compression, _DecompressLZMA):
150152 Represents the LZMA compression algorithm.
151153
152154 Uproot uses ``lzma`` from the Python 3 standard library.
153-
154- In Python 2, ``backports.lzma`` must be installed.
155155 """
156156
157157 def __init__ (self , level ):
@@ -174,8 +174,9 @@ def level(self, value):
174174 raise ValueError ("Compression level must be between 0 and 9 (inclusive)" )
175175 self ._level = int (value )
176176
177- def compress (self , data ):
178- lzma = uproot .extras .lzma ()
177+ def compress (self , data : bytes ) -> bytes :
178+ import lzma
179+
179180 return lzma .compress (data , preset = self ._level )
180181
181182
@@ -184,7 +185,7 @@ class _DecompressLZ4:
184185 _2byte = b"L4"
185186 _method = b"\x01 "
186187
187- def decompress (self , data , uncompressed_bytes = None ):
188+ def decompress (self , data : bytes , uncompressed_bytes = None ) -> bytes :
188189 lz4_block = uproot .extras .lz4_block ()
189190 if uncompressed_bytes is None :
190191 raise ValueError (
@@ -224,7 +225,7 @@ def level(self, value):
224225 raise ValueError ("Compression level must be between 0 and 12 (inclusive)" )
225226 self ._level = int (value )
226227
227- def compress (self , data ) :
228+ def compress (self , data : bytes ) -> bytes :
228229 lz4_block = uproot .extras .lz4_block ()
229230 return lz4_block .compress (data , compression = self ._level , store_size = False )
230231
@@ -245,7 +246,7 @@ def decompressor(self):
245246 self ._decompressor .obj = zstandard .ZstdDecompressor ()
246247 return self ._decompressor .obj
247248
248- def decompress (self , data , uncompressed_bytes = None ):
249+ def decompress (self , data : bytes , uncompressed_bytes = None ) -> bytes :
249250 return self .decompressor .decompress (data )
250251
251252
@@ -288,7 +289,7 @@ def compressor(self):
288289 self ._compressor = zstandard .ZstdCompressor (level = self ._level )
289290 return self ._compressor
290291
291- def compress (self , data ) :
292+ def compress (self , data : bytes ) -> bytes :
292293 return self .compressor .compress (data )
293294
294295
@@ -475,7 +476,7 @@ def hook_after_block(**kwargs):
475476_4byte = struct .Struct ("<I" ) # compressed sizes are 3-byte little endian!
476477
477478
478- def compress (data , compression ) :
479+ def compress (data : bytes , compression : Compression ) -> bytes :
479480 """
480481 Args:
481482 data (bytes, memoryview, or NumPy array): Data to compress.
0 commit comments