GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Revert "gh-118803: Remove `ByteString` from `typing` and `collections.abc` (#118804)" by AlexWaygood · Pull Request #138990 · python/cpython

Conversation

@AlexWaygood

@AlexWaygood AlexWaygood commented Sep 16, 2025 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This is a more-or-less clean revert of commit 2f4db5a. The PR adds back collections.abc.ByteString and typing.ByteString, postponing their removals to Python 3.17.

Prior to 2f4db5a, we had deprecation warnings for ByteString, but they only triggered if you subclassed ByteString or used ByteString as the second argument to isinstance() or issubclass(). Since the removal of ByteString, we've had multiple reports from users that these deprecation warnings have been insufficient and that the removal of ByteString took them by surprise:

  • gh-118803: Remove ByteString from typing and collections.abc #118804 (comment)
  • Remove use of typing.ByteString aio-libs/aiohttp#8408 (comment)
  • Remove ByteString from typing and collections.abc #118803 (comment)

That's because many uses of ByteString do not subclass ByteString or use it as the second argument to isinstance(). Many uses of ByteString 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 the collections.abc and typing modules entirely, it would be much better if we emitted a DeprecationWarning whenever the object is accessed or imported from collections.abc/typing.

Now, there's a good reason why we didn't do that in Python 3.12: ByteString is present both in collections.abc.__all__ and typing.__all__. Naively emitting a deprecation warning every time it was imported or accessed would have caused deprecation warnings to be emitted on every from collections.abc import * or from typing import * statement, which was deemed at the time to be far too noisy and disruptive (#104424). One solution would have been to remove ByteString from collections.abc.__all__ and typing.__all__, but we couldn't do that right away in Python 3.12 as it was a breaking change.

Nonetheless, removing ByteString from collections.abc.__all__ and typing.__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:

  1. Easily add it back at runtime (what this PR does) and backport the add-back PR to 3.14
  2. Remove ByteString from collections.abc.__all__ and typing.__all__ in Python 3.15
  3. Add stronger deprecation warnings at runtime that put us in a good position to remove it entirely in Python 3.17

This 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 when ByteString 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 of ByteString in Python 3.17.

  • Issue: Remove ByteString from typing and collections.abc #118803

📚 Documentation preview 📚: https://cpython-previews--138990.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@AlexWaygood
Revert "pythongh-118803: Remove ByteString from typing and `colle…
be5d2e6
…ctions.abc` (python#118804)"

This reverts commit 2f4db5a.
@AlexWaygood
AlexWaygood requested review from hugovk and sobolevn September 16, 2025 14:50
@AlexWaygood
AlexWaygood requested review from AA-Turner, JelleZijlstra and rhettinger as code owners September 16, 2025 14:50
@bedevere-app bedevere-app Bot added the awaiting core review label Sep 16, 2025
@AlexWaygood AlexWaygood added topic-typing and removed awaiting core review labels Sep 16, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Sep 16, 2025
Remove ByteString from typing and collections.abc #118803
Closed
@AlexWaygood AlexWaygood added the needs backport to 3.14 bugs and security fixes label Sep 16, 2025
@AlexWaygood
blurb and docs
0063249
JelleZijlstra
JelleZijlstra reviewed Sep 16, 2025
View reviewed changes
Comment thread Lib/test/libregrtest/refleak.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

JelleZijlstra
JelleZijlstra reviewed Sep 16, 2025
View reviewed changes
Comment thread Doc/library/typing.rst

.. class:: ByteString(Sequence[int])

This type represents the types :class:`bytes`, :class:`bytearray`,

@JelleZijlstra JelleZijlstra Sep 16, 2025

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AlexWaygood reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@AlexWaygood
revert some reverts
8966dbc
JelleZijlstra
JelleZijlstra approved these changes Sep 16, 2025
View reviewed changes
@bedevere-app bedevere-app Bot added the awaiting merge label Sep 16, 2025
@AlexWaygood
silence this docs nitpick on old whatsnew
74be029
@AlexWaygood
AlexWaygood merged commit 530ddd3 into python:main Sep 16, 2025
@AlexWaygood
AlexWaygood deleted the alex/bring-back-bytestring branch September 16, 2025 15:48
@miss-islington-app

miss-islington-app Bot commented Sep 16, 2025

Copy link
Copy Markdown

Thanks @AlexWaygood for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Sep 16, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 16, 2025
@AlexWaygood @miss-islington
Revert "pythongh-118803: Remove ByteString from typing and `colle…
997a9b9
…ctions.abc` (pythonGH-118804)" (pythonGH-138990)

(cherry picked from commit 530ddd3)

Co-authored-by: Alex Waygood <[email protected]>
@bedevere-app

bedevere-app Bot commented Sep 16, 2025

Copy link
Copy Markdown

GH-138995 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Sep 16, 2025
hugovk pushed a commit that referenced this pull request Sep 17, 2025
@miss-islington @AlexWaygood
[3.14] Revert "gh-118803: Remove ByteString from typing and `coll…
7bba99c
…ections.abc` (GH-118804)" (GH-138990) (#138995)

Revert "gh-118803: Remove `ByteString` from `typing` and `collections.abc` (GH-118804)" (GH-138990)
(cherry picked from commit 530ddd3)

Co-authored-by: Alex Waygood <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@JelleZijlstra JelleZijlstra JelleZijlstra approved these changes
@hugovk hugovk Awaiting requested review from hugovk
@sobolevn sobolevn Awaiting requested review from sobolevn
@rhettinger rhettinger Awaiting requested review from rhettinger rhettinger is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

topic-typing

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@AlexWaygood @JelleZijlstra
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.