Skip to content

Commit b42268c

Browse files
committed
use Buffer instead of ByteString
`ByteString` was [deprecated](https://docs.python.org/3.12/whatsnew/3.12.html#deprecated) in Python 3.12 and [removed](https://docs.python.org/3.14/whatsnew/3.14.html#collections-abc) in 3.14. `collections.abc.Buffer` is available since Python 3.12. Fixes #238 .
1 parent 9eb5694 commit b42268c

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

zstandard/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
import io
1919
import os
2020
import platform
21-
from typing import ByteString
21+
import sys
22+
if sys.version_info >= (3, 12):
23+
from collections.abc import Buffer
24+
else:
25+
from typing import ByteString as Buffer
2226

2327
# Some Python implementations don't support C extensions. That's why we have
2428
# a CFFI implementation in the first place. The code here import one of our
@@ -174,7 +178,7 @@ def open(
174178
return fh
175179

176180

177-
def compress(data: ByteString, level: int = 3) -> bytes:
181+
def compress(data: Buffer, level: int = 3) -> bytes:
178182
"""Compress source data using the zstd compression format.
179183
180184
This performs one-shot compression using basic/default compression
@@ -192,7 +196,7 @@ def compress(data: ByteString, level: int = 3) -> bytes:
192196
return cctx.compress(data)
193197

194198

195-
def decompress(data: ByteString, max_output_size: int = 0) -> bytes:
199+
def decompress(data: Buffer, max_output_size: int = 0) -> bytes:
196200
"""Decompress a zstd frame into its original data.
197201
198202
This performs one-shot decompression using basic/default compression

0 commit comments

Comments
 (0)