python-zstandard icon indicating copy to clipboard operation
python-zstandard copied to clipboard

typing.Bytes string will be removed in Python 3.14

Open mxmlnkn opened this issue 1 year ago • 5 comments

I was trying to use this module in Python 3.14.0-alpha.0, and encountered this error:

Traceback:
/opt/hostedtoolcache/Python/3.14.0-alpha.0/x64/lib/python3.14/importlib/__init__.py:88: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
core/tests/test_BlockParallelReaders.py:19: in <module>
    import zstandard
/opt/hostedtoolcache/Python/3.14.0-alpha.0/x64/lib/python3.14/site-packages/zstandard/__init__.py:21: in <module>
    from typing import ByteString
E   ImportError: cannot import name 'ByteString' from 'typing' (/opt/hostedtoolcache/Python/3.14.0-alpha.0/x64/lib/python3.14/typing.py)
0 assertions tested.

Looking at the changelog, it seems that typing.ByteString has been removed.

mxmlnkn avatar Sep 15 '24 21:09 mxmlnkn

Just got the same filed downstream in Fedora: https://bugzilla.redhat.com/show_bug.cgi?id=2326925 . Our Python maintainers caught this, too.

rathann avatar Nov 18 '24 10:11 rathann

Python 3.13 ByteString documentation suggests using collections.abc.Buffer instead.

rathann avatar Mar 28 '25 15:03 rathann

diff -up zstandard-0.23.0/zstandard/__init__.py.py314 zstandard-0.23.0/zstandard/__init__.py
--- zstandard-0.23.0/zstandard/__init__.py.py314        2024-07-14 23:58:50.000000000 +0200
+++ zstandard-0.23.0/zstandard/__init__.py      2025-03-28 17:16:47.339256930 +0100
@@ -18,7 +18,10 @@ import io
 import os
 import platform

-from typing import ByteString
+try:
+    from typing import ByteString
+except ImportError:
+    from collections.abc import Buffer as ByteString

 # Some Python implementations don't support C extensions. That's why we have
 # a CFFI implementation in the first place. The code here import one of our

The above patch makes it build with Python 3.14a6. @indygreg shall I submit a PR?

rathann avatar Mar 28 '25 16:03 rathann

@rathann Yes please, that would be very helpful! My only recommendation would be to not catch an exception in the new common case and instead use a conditional:

if sys.version_info >= (3, 12):
    from collections.abc import Buffer
else:
    from typing import ByteString as Buffer

ofek avatar Apr 18 '25 01:04 ofek

@ofek how about #262 ?

rathann avatar Apr 23 '25 20:04 rathann