Skip to content

Commit 58350a4

Browse files
committed
Address Adam's feedback
1 parent fb00877 commit 58350a4

File tree

5 files changed

+80
-40
lines changed

5 files changed

+80
-40
lines changed

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

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@ Pending removal in Python 3.17
55

66
- :class:`collections.abc.ByteString` is scheduled for removal in Python 3.17.
77

8-
``ByteString`` was originally intended to be an abstract type that would serve as a
9-
supertype of both :class:`bytes` and :class:`bytearray`, but its semantics were never
10-
clearly specified, and it was never understood properly by type checkers. See
11-
:pep:`PEP 688 <688#current-options>` for more details.
8+
Use ``isinstance(obj, collections.abc.Buffer)`` to test if ``obj``
9+
implements the :ref:`buffer protocol <bufferobjects>` at runtime. For use
10+
in type annotations, either use :class:`Buffer` or a union that explicitly
11+
specifies the types your code supports (e.g.,
12+
``bytes | bytearray | memoryview``).
13+
14+
:class:`!ByteString` was originally intended to be an abstract class that
15+
would serve as a supertype of both :class:`bytes` and :class:`bytearray`.
16+
However, since the ABC never had any methods, knowing that an object was an
17+
instance of :class:`!ByteString` never actually told you anything useful
18+
about the object. Other common buffer types such as :class:`memoryview`
19+
were also never understood as subtypes of :class:`!ByteString` (either at
20+
runtime or by static type checkers).
21+
22+
See :pep:`PEP 688 <688#current-options>` for more details.
23+
(Contributed by Shantanu Jain in :gh:`91896`.)
1224

13-
Prefer :class:`~collections.abc.Sequence` or :class:`~collections.abc.Buffer`. For
14-
use in type annotations, prefer a union, like ``bytes | bytearray``, or
15-
:class:`collections.abc.Buffer`. (Contributed by Shantanu Jain in :gh:`91896`.)
1625

1726
* :mod:`typing`:
1827

@@ -24,12 +33,19 @@ Pending removal in Python 3.17
2433
- :class:`typing.ByteString`, deprecated since Python 3.9, is scheduled for removal in
2534
Python 3.17.
2635

27-
``ByteString`` was originally intended to be an abstract type that would serve as a
28-
supertype of both :class:`bytes` and :class:`bytearray`, but its semantics were never
29-
clearly specified, and it was never understood properly by type checkers. See
30-
:pep:`PEP 688 <688#current-options>` for more details.
31-
32-
Prefer :class:`~collections.abc.Sequence` or :class:`~collections.abc.Buffer`. For
33-
use in type annotations, prefer a union, like ``bytes | bytearray``, or
34-
:class:`collections.abc.Buffer`.
36+
Use ``isinstance(obj, collections.abc.Buffer)`` to test if ``obj``
37+
implements the :ref:`buffer protocol <bufferobjects>` at runtime. For use
38+
in type annotations, either use :class:`~collections.abc.Buffer` or a union
39+
that explicitly specifies the types your code supports (e.g.,
40+
``bytes | bytearray | memoryview``).
41+
42+
:class:`!ByteString` was originally intended to be an abstract class that
43+
would serve as a supertype of both :class:`bytes` and :class:`bytearray`.
44+
However, since the ABC never had any methods, knowing that an object was an
45+
instance of :class:`!ByteString` never actually told you anything useful
46+
about the object. Other common buffer types such as :class:`memoryview`
47+
were also never understood as subtypes of :class:`!ByteString` (either at
48+
runtime or by static type checkers).
49+
50+
See :pep:`PEP 688 <688#current-options>` for more details.
3551
(Contributed by Shantanu Jain in :gh:`91896`.)

Doc/library/collections.abc.rst

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,21 @@ Collections Abstract Base Classes -- Detailed Descriptions
292292
.. deprecated-removed:: 3.12 3.17
293293
The :class:`ByteString` ABC has been deprecated.
294294

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-
301-
For use in type annotations, prefer a union, like ``bytes | bytearray``, or
302-
:class:`collections.abc.Buffer`.
303-
For use as an ABC, prefer :class:`Sequence` or :class:`collections.abc.Buffer`.
295+
Use ``isinstance(obj, collections.abc.Buffer)`` to test if ``obj``
296+
implements the :ref:`buffer protocol <bufferobjects>` at runtime. For use
297+
in type annotations, either use :class:`Buffer` or a union that
298+
explicitly specifies the types your code supports (e.g.,
299+
``bytes | bytearray | memoryview``).
300+
301+
:class:`!ByteString` was originally intended to be an abstract class that
302+
would serve as a supertype of both :class:`bytes` and :class:`bytearray`.
303+
However, since the ABC never had any methods, knowing that an object was
304+
an instance of :class:`!ByteString` never actually told you anything
305+
useful about the object. Other common buffer types such as
306+
:class:`memoryview` were also never understood as subtypes of
307+
:class:`!ByteString` (either at runtime or by static type checkers).
308+
309+
See :pep:`PEP 688 <688#current-options>` for more details.
304310

305311
.. class:: Set
306312
MutableSet

Doc/library/typing.rst

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3792,14 +3792,23 @@ Aliases to container ABCs in :mod:`collections.abc`
37923792

37933793
Deprecated alias to :class:`collections.abc.ByteString`.
37943794

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.
3795+
Use ``isinstance(obj, collections.abc.Buffer)`` to test if ``obj``
3796+
implements the :ref:`buffer protocol <bufferobjects>` at runtime. For use in
3797+
type annotations, either use :class:`~collections.abc.Buffer` or a union
3798+
that explicitly specifies the types your code supports (e.g.,
3799+
``bytes | bytearray | memoryview``).
3800+
3801+
:class:`!ByteString` was originally intended to be an abstract class that
3802+
would serve as a supertype of both :class:`bytes` and :class:`bytearray`.
3803+
However, since the ABC never had any methods, knowing that an object was an
3804+
instance of :class:`!ByteString` never actually told you anything useful
3805+
about the object. Other common buffer types such as :class:`memoryview` were
3806+
also never understood as subtypes of :class:`!ByteString` (either at runtime
3807+
or by static type checkers).
3808+
3809+
See :pep:`PEP 688 <688#current-options>` for more details.
38003810

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

38043813
.. class:: Collection(Sized, Iterable[T_co], Container[T_co])
38053814

Doc/whatsnew/3.12.rst

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,13 +1193,21 @@ Deprecated
11931193

11941194
* :mod:`collections.abc`: Deprecated :class:`collections.abc.ByteString`.
11951195

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-
1201-
Prefer :class:`Sequence` or :class:`collections.abc.Buffer`.
1202-
For use in type annotations, prefer a union, like ``bytes | bytearray``, or :class:`collections.abc.Buffer`.
1196+
Use ``isinstance(obj, collections.abc.Buffer)`` to test if ``obj`` implements
1197+
the :ref:`buffer protocol <bufferobjects>` at runtime. For use in type
1198+
annotations, either use :class:`~collections.abc.Buffer` or a union
1199+
that explicitly specifies the types your code supports (e.g.,
1200+
``bytes | bytearray | memoryview``).
1201+
1202+
:class:`!ByteString` was originally intended to be an abstract class that
1203+
would serve as a supertype of both :class:`bytes` and :class:`bytearray`.
1204+
However, since the ABC never had any methods, knowing that an object was an
1205+
instance of :class:`!ByteString` never actually told you anything useful
1206+
about the object. Other common buffer types such as :class:`memoryview` were
1207+
also never understood as subtypes of :class:`!ByteString` (either at
1208+
runtime or by static type checkers).
1209+
1210+
See :pep:`PEP 688 <688#current-options>` for more details.
12031211
(Contributed by Shantanu Jain in :gh:`91896`.)
12041212

12051213
* :mod:`datetime`: :class:`datetime.datetime`'s :meth:`~datetime.datetime.utcnow` and

Lib/_collections_abc.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,9 +1085,10 @@ class ByteString(Sequence, metaclass=_DeprecateByteStringMeta):
10851085
"""Deprecated ABC serving as a common supertype of ``bytes`` and ``bytearray``.
10861086
10871087
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``.
1088+
Use ``isinstance(obj, collections.abc.Buffer)`` to test if ``obj``
1089+
implements the buffer protocol at runtime. For use in type annotations,
1090+
either use ``Buffer`` or a union that explicitly specifies the types your
1091+
code supports (e.g., ``bytes | bytearray | memoryview``).
10911092
"""
10921093

10931094
__slots__ = ()

0 commit comments

Comments
 (0)