Skip to content

typing.Bytes string will be removed in Python 3.14 #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Tracked by #6604
mxmlnkn opened this issue Sep 15, 2024 · 5 comments · May be fixed by #262
Open
Tracked by #6604

typing.Bytes string will be removed in Python 3.14 #238

mxmlnkn opened this issue Sep 15, 2024 · 5 comments · May be fixed by #262

Comments

@mxmlnkn
Copy link

mxmlnkn commented Sep 15, 2024

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.

@rathann
Copy link
Contributor

rathann commented Nov 18, 2024

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

@rathann
Copy link
Contributor

rathann commented Mar 28, 2025

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

@rathann
Copy link
Contributor

rathann commented Mar 28, 2025

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?

@ofek
Copy link

ofek commented Apr 18, 2025

@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

rathann added a commit to rathann/python-zstandard that referenced this issue Apr 23, 2025
`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 indygreg#238 .
@rathann rathann linked a pull request Apr 23, 2025 that will close this issue
@rathann
Copy link
Contributor

rathann commented Apr 23, 2025

@ofek how about #262 ?

rathann added a commit to rathann/python-zstandard that referenced this issue Apr 23, 2025
`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 indygreg#238 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants