-
-
Notifications
You must be signed in to change notification settings - Fork 32.9k
Revert "gh-118803: Remove ByteString
from typing
and collections.abc
(#118804)"
#138990
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
Merged
AlexWaygood
merged 4 commits into
python:main
from
AlexWaygood:alex/bring-back-bytestring
Sep 16, 2025
Merged
Revert "gh-118803: Remove ByteString
from typing
and collections.abc
(#118804)"
#138990
AlexWaygood
merged 4 commits into
python:main
from
AlexWaygood:alex/bring-back-bytestring
Sep 16, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ctions.abc` (python#118804)" This reverts commit 2f4db5a.
@@ -3788,6 +3788,14 @@ Aliases to container ABCs in :mod:`collections.abc` | |||
:class:`collections.abc.Set` now supports subscripting (``[]``). | |||
See :pep:`585` and :ref:`types-genericalias`. | |||
|
|||
.. class:: ByteString(Sequence[int]) | |||
|
|||
This type represents the types :class:`bytes`, :class:`bytearray`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should also change this documentation to make it clear that the type has no coherent meaning. Can do that later though.
JelleZijlstra
approved these changes
Sep 16, 2025
Thanks @AlexWaygood for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Sep 16, 2025
…ctions.abc` (pythonGH-118804)" (pythonGH-138990) (cherry picked from commit 530ddd3e06a425b8bb9e8afb657dc7711a5aa2f9) Co-authored-by: Alex Waygood <[email protected]>
GH-138995 is a backport of this pull request to the 3.14 branch. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a more-or-less clean revert of commit 2f4db5a. The PR adds back
collections.abc.ByteString
andtyping.ByteString
, postponing their removals to Python 3.17.Prior to 2f4db5a, we had deprecation warnings for
ByteString
, but they only triggered if you subclassedByteString
or usedByteString
as the second argument toisinstance()
orissubclass()
. Since the removal ofByteString
, we've had multiple reports from users that these deprecation warnings have been insufficient and that the removal ofByteString
took them by surprise:ByteString
fromtyping
andcollections.abc
#118804 (comment)typing.ByteString
aio-libs/aiohttp#8408 (comment)ByteString
fromtyping
andcollections.abc
#118803 (comment)That's because many uses of
ByteString
do not subclassByteString
or use it as the second argument toisinstance()
. Many uses ofByteString
simply use it as a type annotation, and simply using it as a type annotation would not be sufficient to trigger a runtime deprecation warning informing you that the object would be removed in Python 3.14. Prior to removing the object from thecollections.abc
andtyping
modules entirely, it would be much better if we emitted aDeprecationWarning
whenever the object is accessed or imported fromcollections.abc
/typing
.Now, there's a good reason why we didn't do that in Python 3.12:
ByteString
is present both incollections.abc.__all__
andtyping.__all__
. Naively emitting a deprecation warning every time it was imported or accessed would have caused deprecation warnings to be emitted on everyfrom collections.abc import *
orfrom typing import *
statement, which was deemed at the time to be far too noisy and disruptive (#104424). One solution would have been to removeByteString
fromcollections.abc.__all__
andtyping.__all__
, but we couldn't do that right away in Python 3.12 as it was a breaking change.Nonetheless, removing
ByteString
fromcollections.abc.__all__
andtyping.__all__
is much less of a breaking change than removing it entirely without prominent runtime deprecation warnings. Now that we're in a place where it's been deprecated in the docs for 2 releases and had some runtime deprecation warnings for 2 releases, I think we're now in a position where we can:ByteString
fromcollections.abc.__all__
andtyping.__all__
in Python 3.15This PR should strictly improve backwards compatibility. It will not break anything for users who have already removed their uses of
ByteString
; they will simply be extremely well prepared for whenByteString
is removed for good in Python 3.17. For users who have been unaware of the deprecation up till now, however (and there may be many such users that we don't know about in closed-source projects), this will mean that they are given much better notice that they should adapt their code for the forthcoming removal ofByteString
in Python 3.17.ByteString
fromtyping
andcollections.abc
#118803📚 Documentation preview 📚: https://cpython-previews--138990.org.readthedocs.build/