Repository navigation
Remove ByteString from typing and collections.abc #118803
Description
Activity
- addedtype-featureA feature request or enhancementA feature request or enhancement3.14bugs and security fixesbugs and security fixes
on May 8, 2024 - added a commit that references this issue
on May 8, 2024 Tbh I was a bit surprised that it didn't raise any DeprecationWarning on 3.13. Looking at #118804 it seems that was only emitted on
isinstancechecks. Most examples I've seen while testing 3.14 just import it at runtime to use as annotation.It's a bit unfortunate to not have gotten a warning for it earlier as a few packages will now require immediate fixes for 3.14. Not sure if it would be worth it to revert the removal and add a proper DeprecationWarning on import (i.e. in
typing.__getattr__)?Reacted by Joao S. O. BuenoReacted by vivodiReacted by vivodiI'd be OK with that. This sort of removal can be pretty disruptive since libraries using it will usually be using a
fromimport, so users who need those libraries will be completely unable to even import the library on 3.14.What are some examples of libraries still using this?
Reacted by vivodiReacted by vivodiI'm also fine with doing a longer deprecation period here. The reason we didn't emit deprecation warnings when it was imported/accessed from
typing.pyinitially was that it's included intyping.__all__, which means thatfrom typing import *would have led to a deprecation warning being emitted. We realised that doing that is actually fairly common, and we couldn't remove it from__all__because that itself was a breaking change.Now that we've had deprecation warnings in the docs for 2 years, though (and some deprecation warnings at runtime), I think it would be fine to remove
ByteStringfromtyping.__all__, removeByteStringfromcollections.abc.__all__, and emit more aggressive deprecation warnings that trigger when you import it from typing or access it as an attribute from the module. It's still breaking (people will getNameErrors if they were relying onfrom typing import *to importByteStringfor them), but it's much less breaking than what we have now, which isByteStringno longer existing at all.Reacted by vivodiReacted by vivodiWhat are some examples of libraries still using this?
It was a while back (and they obviously no longer use it following my PR), but I was pretty concerned when
aiohttpsaid that they hadn't seen any deprecation warnings about this in aio-libs/aiohttp#8408 (comment). I meant to propose extending the deprecation period, but lost track of it :-(Reacted by vivodiReacted by vivodiWhat are some examples of libraries still using this?
I've only seen it a couple of times so far. Most cases have already been fixed for some time now:
crc-> Fixed in5.0(Nicoretti/crc@2ae4871). For Home Assistant we have a dependency which still (unnecessarily) pins the version to<5. Will work to update that instead.pynacl-> Fixed last year in Fix compatibility with Python 3.14.0a1 pyca/pynacl#848 but no new release yet.
Reacted by vivodiReacted by vivodiAnyone interested in sending a PR to restore it for 3.14?
Reacted by vivodiReacted by vivodiI think that we should check top 10000 packages for its usages. If there are many existing ones - it might be a good idea to restore it. But, if there are just several - then we should probably move forward, it was deprecated for 5 versions already, there was a lot of time to change the code
.. deprecated-removed:: 3.9 3.14. It is not hard to fix in the library code asByteString = bytes | bytearray.18 remaining items
- added a commit that references this issue
on Sep 16, 2025 - added a commit that references this issue
on Sep 17, 2025 - added a commit that references this issue
on Sep 18, 2025 We've now done everything we plan to do here until 3.17
Reacted by Hugo van Kemenade- moved this from Todo to Done in Release and Deferred blockers 🚫
on Sep 18, 2025 - added a commit that references this issue
on Sep 19, 2025
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Feature or enhancement
It was deprecated and scheduled for removal in 3.14
Original issue: #91896
Ref: 09b7695
Linked PRs
ByteStringfromtypingandcollections.abc#118804ByteStringfromtypingandcollections.abc(#118804)" #138990ByteStringfromtypingandcollections.abc(GH-118804)" (GH-138990) #138995ByteStringdeprecation #139115ByteStringdeprecations louder; removeByteStringfromtyping.__all__andcollections.abc.__all__#139127ByteStringdeprecation (GH-139115) #139136ByteStringdeprecation (#139115) #139137ByteString#139171