Skip to content

Commit 4929094

Browse files
authored
Fix support for Python 3.14 built without zstd (aio-libs#11611)
1 parent 9f718eb commit 4929094

3 files changed

Lines changed: 11 additions & 9 deletions

File tree

‎CHANGES/11603.bugfix.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed Python 3.14 support when built without ``zstd`` support -- by :user:`JacobHenner`.

‎CONTRIBUTORS.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ Ivan Lakovic
177177
Ivan Larin
178178
J. Nick Koston
179179
Jacob Champion
180+
Jacob Henner
180181
Jaesung Lee
181182
Jake Davis
182183
Jakob Ackermann

‎aiohttp/compression_utils.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@
2121
except ImportError:
2222
HAS_BROTLI = False
2323

24-
if sys.version_info >= (3, 14):
25-
import compression.zstd # noqa: I900
24+
try:
25+
from compression.zstd import ( # type: ignore[import-not-found] # noqa: I900
26+
ZstdDecompressor,
27+
)
2628

2729
HAS_ZSTD = True
28-
else:
30+
except ImportError:
2931
try:
30-
import zstandard
32+
from zstandard import ZstdDecompressor
3133

3234
HAS_ZSTD = True
3335
except ImportError:
3436
HAS_ZSTD = False
3537

38+
3639
MAX_SYNC_CHUNK_SIZE = 1024
3740

3841

@@ -297,13 +300,10 @@ def __init__(self) -> None:
297300
"The zstd decompression is not available. "
298301
"Please install `zstandard` module"
299302
)
300-
if sys.version_info >= (3, 14):
301-
self._obj = compression.zstd.ZstdDecompressor()
302-
else:
303-
self._obj = zstandard.ZstdDecompressor()
303+
self._obj = ZstdDecompressor()
304304

305305
def decompress_sync(self, data: bytes) -> bytes:
306-
return self._obj.decompress(data)
306+
return self._obj.decompress(data) # type: ignore[no-any-return]
307307

308308
def flush(self) -> bytes:
309309
return b""

0 commit comments

Comments
 (0)