Skip to content

Commit 45fbbc6

Browse files
committed
gh-118803: Improve documentation around ByteString deprecation
1 parent 70ad1b3 commit 45fbbc6

File tree

5 files changed

+44
-10
lines changed

5 files changed

+44
-10
lines changed

Doc/deprecations/pending-removal-in-3.17.rst

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,27 @@ Pending removal in Python 3.17
99
3.17. Users should use documented introspection helpers like :func:`typing.get_origin`
1010
and :func:`typing.get_args` instead of relying on private implementation details.
1111
- :class:`typing.ByteString`, deprecated since Python 3.9, is scheduled for removal in
12-
Python 3.17. Prefer :class:`~collections.abc.Sequence` or
13-
:class:`~collections.abc.Buffer`. For use in type annotations, prefer a union, like
14-
``bytes | bytearray``, or :class:`collections.abc.Buffer`.
12+
Python 3.17.
13+
14+
``ByteString`` was originally intended to be an abstract type that would serve as a
15+
supertype of both :class:`bytes` and :class:`bytearray`, but its semantics were never
16+
clearly specified, and it was never understood properly by type checkers. See
17+
:pep:`PEP 688 <688#current-options>` for more details.
18+
19+
Prefer :class:`~collections.abc.Sequence` or :class:`~collections.abc.Buffer`. For
20+
use in type annotations, prefer a union, like ``bytes | bytearray``, or
21+
:class:`collections.abc.Buffer`.
1522
(Contributed by Shantanu Jain in :gh:`91896`.)
1623

1724
* :mod:`collections.abc`:
1825

19-
- :class:`collections.abc.ByteString` is scheduled for removal in Python 3.17. Prefer
20-
:class:`~collections.abc.Sequence` or :class:`~collections.abc.Buffer`. For use in
21-
type annotations, prefer a union, like ``bytes | bytearray``, or
26+
- :class:`collections.abc.ByteString` is scheduled for removal in Python 3.17.
27+
28+
``ByteString`` was originally intended to be an abstract type that would serve as a
29+
supertype of both :class:`bytes` and :class:`bytearray`, but its semantics were never
30+
clearly specified, and it was never understood properly by type checkers. See
31+
:pep:`PEP 688 <688#current-options>` for more details.
32+
33+
Prefer :class:`~collections.abc.Sequence` or :class:`~collections.abc.Buffer`. For
34+
use in type annotations, prefer a union, like ``bytes | bytearray``, or
2235
:class:`collections.abc.Buffer`. (Contributed by Shantanu Jain in :gh:`91896`.)

Doc/library/collections.abc.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,13 @@ Collections Abstract Base Classes -- Detailed Descriptions
291291

292292
.. deprecated-removed:: 3.12 3.17
293293
The :class:`ByteString` ABC has been deprecated.
294+
295+
``ByteString`` was originally intended to be an abstract type that would
296+
serve as a supertype of both :class:`bytes` and :class:`bytearray`, but
297+
its semantics were never clearly specified, and it was never understood
298+
properly by type checkers. See :pep:`PEP 688 <688#current-options>` for
299+
more details.
300+
294301
For use in type annotations, prefer a union, like ``bytes | bytearray``, or
295302
:class:`collections.abc.Buffer`.
296303
For use as an ABC, prefer :class:`Sequence` or :class:`collections.abc.Buffer`.

Doc/library/typing.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3790,8 +3790,13 @@ Aliases to container ABCs in :mod:`collections.abc`
37903790

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

3793-
This type represents the types :class:`bytes`, :class:`bytearray`,
3794-
and :class:`memoryview` of byte sequences.
3793+
Deprecated alias to :class:`collections.abc.ByteString`.
3794+
3795+
``ByteString`` was originally intended to be an abstract type that would
3796+
serve as a supertype of both :class:`bytes` and :class:`bytearray`. However,
3797+
its semantics were never clearly specified, and it was never understood
3798+
properly by type checkers. See :pep:`PEP 688 <688#current-options>` for more
3799+
details.
37953800

37963801
.. deprecated-removed:: 3.9 3.17
37973802
Prefer :class:`collections.abc.Buffer`, or a union like ``bytes | bytearray | memoryview``.

Doc/whatsnew/3.12.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,12 @@ Deprecated
11921192
(Contributed by Prince Roshan in :gh:`103636`.)
11931193

11941194
* :mod:`collections.abc`: Deprecated :class:`collections.abc.ByteString`.
1195+
1196+
``ByteString`` was originally intended to be an abstract type that would
1197+
serve as a supertype of both :class:`bytes` and :class:`bytearray`, but its
1198+
semantics were never clearly specified, and it was never understood properly
1199+
by type checkers. See :pep:`PEP 688 <688#current-options>` for more details.
1200+
11951201
Prefer :class:`Sequence` or :class:`collections.abc.Buffer`.
11961202
For use in type annotations, prefer a union, like ``bytes | bytearray``, or :class:`collections.abc.Buffer`.
11971203
(Contributed by Shantanu Jain in :gh:`91896`.)

Lib/_collections_abc.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,9 +1082,12 @@ def __instancecheck__(cls, instance):
10821082
return super().__instancecheck__(instance)
10831083

10841084
class ByteString(Sequence, metaclass=_DeprecateByteStringMeta):
1085-
"""This unifies bytes and bytearray.
1085+
"""Deprecated ABC serving as a common supertype of ``bytes`` and ``bytearray``.
10861086
1087-
XXX Should add all their methods.
1087+
This ABC is scheduled for removal in Python 3.17.
1088+
For use in type annotations, prefer a union, like ``bytes | bytearray``, or
1089+
``collections.abc.Buffer``. For use as an ABC, prefer ``Sequence`` or
1090+
``collections.abc.Buffer``.
10881091
"""
10891092

10901093
__slots__ = ()

0 commit comments

Comments
 (0)