gh-91896: Improve visibility of `ByteString` deprecation warnings by AlexWaygood · Pull Request #104294 · python/cpython
Conversation
#102096 added deprecation warnings for collections.abc.ByteString, but these warnings are currently only emitted on subclassing ByteString or calling isinstance() against it. Importing ByteString or accessing it via import collections.abc; collections.abc.ByteString does not currently trigger any warnings, meaning somebody who's just using the class for type annotations might not get any warning that the class will be removed in 3.14. Moreover, the isinstance() deprecation warnings are only emitted on isinstance() checks against collections.abc.ByteString, not on isinstance() checks against typing.ByteString. The docs update that we just made in 1f56795 says that typing.ByteString will also be removed in Python 3.14, so we should emit the same deprecation warnings for typing.ByteString.
This PR adds deprecation warnings for:
from collections.abc import ByteStringimport collections.abc; collections.abc.ByteStringfrom typing import ByteStringimport typing; typing.ByteStringisinstance(b"", typing.ByteString)
(Skipping news as I think the news entry in #102096 should be enough)
I'm not opposed to this but think it isn't necessary. We aren't required to emit warnings. The deprecation notices in whatsnew and the docs will suffice. This doubly true for ByteString which like has low use.
I'm not opposed to this but think it isn't necessary. We aren't required to emit warnings. The deprecation notices in whatsnew and the docs will suffice. This doubly true for ByteString which like has low use.
I don't feel strongly about this, and perhaps it isn't strictly necessary, but I would prefer maximum visibility, personally. I think it will help users if they get a clear runtime warning when they use the symbol in a type annotation, before the symbol is removed.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! While collections.abc.ByteString is extremely low use, there is some use of typing.ByteString as an annotation out there, for which this could help.
Either way we should lean on type checkers for this deprecation as well, since we won't get warnings in stub files or some from __future__ import annotations scenarios.
This was referenced