Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions Doc/deprecations/pending-removal-in-3.17.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,27 @@ Pending removal in Python 3.17
3.17. Users should use documented introspection helpers like :func:`typing.get_origin`
and :func:`typing.get_args` instead of relying on private implementation details.
- :class:`typing.ByteString`, deprecated since Python 3.9, is scheduled for removal in
Python 3.17. Prefer :class:`~collections.abc.Sequence` or
:class:`~collections.abc.Buffer`. For use in type annotations, prefer a union, like
``bytes | bytearray``, or :class:`collections.abc.Buffer`.
Python 3.17.

``ByteString`` was originally intended to be an abstract type that would serve as a
supertype of both :class:`bytes` and :class:`bytearray`, but its semantics were never
clearly specified, and it was never understood properly by type checkers. See
:pep:`PEP 688 <688#current-options>` for more details.

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

* :mod:`collections.abc`:

- :class:`collections.abc.ByteString` is scheduled for removal in Python 3.17. Prefer
:class:`~collections.abc.Sequence` or :class:`~collections.abc.Buffer`. For use in
type annotations, prefer a union, like ``bytes | bytearray``, or
- :class:`collections.abc.ByteString` is scheduled for removal in Python 3.17.

``ByteString`` was originally intended to be an abstract type that would serve as a
supertype of both :class:`bytes` and :class:`bytearray`, but its semantics were never
clearly specified, and it was never understood properly by type checkers. See
:pep:`PEP 688 <688#current-options>` for more details.

Prefer :class:`~collections.abc.Sequence` or :class:`~collections.abc.Buffer`. For
use in type annotations, prefer a union, like ``bytes | bytearray``, or
:class:`collections.abc.Buffer`. (Contributed by Shantanu Jain in :gh:`91896`.)
7 changes: 7 additions & 0 deletions Doc/library/collections.abc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,13 @@ Collections Abstract Base Classes -- Detailed Descriptions

.. deprecated-removed:: 3.12 3.17
The :class:`ByteString` ABC has been deprecated.

``ByteString`` was originally intended to be an abstract type that would
serve as a supertype of both :class:`bytes` and :class:`bytearray`, but
its semantics were never clearly specified, and it was never understood
properly by type checkers. See :pep:`PEP 688 <688#current-options>` for
more details.

For use in type annotations, prefer a union, like ``bytes | bytearray``, or
:class:`collections.abc.Buffer`.
For use as an ABC, prefer :class:`Sequence` or :class:`collections.abc.Buffer`.
Expand Down
9 changes: 7 additions & 2 deletions Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3790,8 +3790,13 @@ Aliases to container ABCs in :mod:`collections.abc`

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

This type represents the types :class:`bytes`, :class:`bytearray`,
and :class:`memoryview` of byte sequences.
Deprecated alias to :class:`collections.abc.ByteString`.

``ByteString`` was originally intended to be an abstract type that would
serve as a supertype of both :class:`bytes` and :class:`bytearray`. However,
its semantics were never clearly specified, and it was never understood
properly by type checkers. See :pep:`PEP 688 <688#current-options>` for more
details.

.. deprecated-removed:: 3.9 3.17
Prefer :class:`collections.abc.Buffer`, or a union like ``bytes | bytearray | memoryview``.
Expand Down
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,12 @@ Deprecated
(Contributed by Prince Roshan in :gh:`103636`.)

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

``ByteString`` was originally intended to be an abstract type that would
serve as a supertype of both :class:`bytes` and :class:`bytearray`, but its
semantics were never clearly specified, and it was never understood properly
by type checkers. See :pep:`PEP 688 <688#current-options>` for more details.

Prefer :class:`Sequence` or :class:`collections.abc.Buffer`.
For use in type annotations, prefer a union, like ``bytes | bytearray``, or :class:`collections.abc.Buffer`.
(Contributed by Shantanu Jain in :gh:`91896`.)
Expand Down
7 changes: 5 additions & 2 deletions Lib/_collections_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,9 +1082,12 @@ def __instancecheck__(cls, instance):
return super().__instancecheck__(instance)

class ByteString(Sequence, metaclass=_DeprecateByteStringMeta):
"""This unifies bytes and bytearray.
"""Deprecated ABC serving as a common supertype of ``bytes`` and ``bytearray``.

XXX Should add all their methods.
This ABC is scheduled for removal in Python 3.17.
For use in type annotations, prefer a union, like ``bytes | bytearray``, or
``collections.abc.Buffer``. For use as an ABC, prefer ``Sequence`` or
``collections.abc.Buffer``.
"""

__slots__ = ()
Expand Down
Loading