Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2f4db5a

Browse filesBrowse files
authored
gh-118803: Remove ByteString from typing and collections.abc (#118804)
1 parent cb6f75a commit 2f4db5a
Copy full SHA for 2f4db5a

12 files changed

+14
-114
lines changed

‎Doc/library/collections.abc.rst

Copy file name to clipboardExpand all lines: Doc/library/collections.abc.rst
-10Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,6 @@ ABC Inherits from Abstract Methods Mi
141141
``__len__``,
142142
``insert``
143143

144-
:class:`ByteString` :class:`Sequence` ``__getitem__``, Inherited :class:`Sequence` methods
145-
``__len__``
146-
147144
:class:`Set` :class:`Collection` ``__contains__``, ``__le__``, ``__lt__``, ``__eq__``, ``__ne__``,
148145
``__iter__``, ``__gt__``, ``__ge__``, ``__and__``, ``__or__``,
149146
``__len__`` ``__sub__``, ``__xor__``, and ``isdisjoint``
@@ -257,7 +254,6 @@ Collections Abstract Base Classes -- Detailed Descriptions
257254

258255
.. class:: Sequence
259256
MutableSequence
260-
ByteString
261257

262258
ABCs for read-only and mutable :term:`sequences <sequence>`.
263259

@@ -274,12 +270,6 @@ Collections Abstract Base Classes -- Detailed Descriptions
274270
The index() method added support for *stop* and *start*
275271
arguments.
276272

277-
.. deprecated-removed:: 3.12 3.14
278-
The :class:`ByteString` ABC has been deprecated.
279-
For use in typing, prefer a union, like ``bytes | bytearray``, or
280-
:class:`collections.abc.Buffer`.
281-
For use as an ABC, prefer :class:`Sequence` or :class:`collections.abc.Buffer`.
282-
283273
.. class:: Set
284274
MutableSet
285275

‎Doc/library/stdtypes.rst

Copy file name to clipboardExpand all lines: Doc/library/stdtypes.rst
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5061,7 +5061,6 @@ list is non-exhaustive.
50615061
* :class:`collections.abc.MutableMapping`
50625062
* :class:`collections.abc.Sequence`
50635063
* :class:`collections.abc.MutableSequence`
5064-
* :class:`collections.abc.ByteString`
50655064
* :class:`collections.abc.MappingView`
50665065
* :class:`collections.abc.KeysView`
50675066
* :class:`collections.abc.ItemsView`

‎Doc/library/typing.rst

Copy file name to clipboardExpand all lines: Doc/library/typing.rst
-12Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3502,14 +3502,6 @@ Aliases to container ABCs in :mod:`collections.abc`
35023502
:class:`collections.abc.Set` now supports subscripting (``[]``).
35033503
See :pep:`585` and :ref:`types-genericalias`.
35043504

3505-
.. class:: ByteString(Sequence[int])
3506-
3507-
This type represents the types :class:`bytes`, :class:`bytearray`,
3508-
and :class:`memoryview` of byte sequences.
3509-
3510-
.. deprecated-removed:: 3.9 3.14
3511-
Prefer :class:`collections.abc.Buffer`, or a union like ``bytes | bytearray | memoryview``.
3512-
35133505
.. class:: Collection(Sized, Iterable[T_co], Container[T_co])
35143506

35153507
Deprecated alias to :class:`collections.abc.Collection`.
@@ -3875,10 +3867,6 @@ convenience. This is subject to change, and not all deprecations are listed.
38753867
- 3.9
38763868
- Undecided (see :ref:`deprecated-aliases` for more information)
38773869
- :pep:`585`
3878-
* - :class:`typing.ByteString`
3879-
- 3.9
3880-
- 3.14
3881-
- :gh:`91896`
38823870
* - :data:`typing.Text`
38833871
- 3.11
38843872
- Undecided

‎Doc/whatsnew/3.12.rst

Copy file name to clipboardExpand all lines: Doc/whatsnew/3.12.rst
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ Deprecated
11831183
replaced by :data:`calendar.JANUARY` and :data:`calendar.FEBRUARY`.
11841184
(Contributed by Prince Roshan in :gh:`103636`.)
11851185

1186-
* :mod:`collections.abc`: Deprecated :class:`collections.abc.ByteString`.
1186+
* :mod:`collections.abc`: Deprecated :class:`!collections.abc.ByteString`.
11871187
Prefer :class:`Sequence` or :class:`collections.abc.Buffer`.
11881188
For use in typing, prefer a union, like ``bytes | bytearray``, or :class:`collections.abc.Buffer`.
11891189
(Contributed by Shantanu Jain in :gh:`91896`.)
@@ -1293,7 +1293,7 @@ Deprecated
12931293
:class:`collections.abc.Hashable` and :class:`collections.abc.Sized` respectively, are
12941294
deprecated. (:gh:`94309`.)
12951295

1296-
* :class:`typing.ByteString`, deprecated since Python 3.9, now causes a
1296+
* :class:`!typing.ByteString`, deprecated since Python 3.9, now causes a
12971297
:exc:`DeprecationWarning` to be emitted when it is used.
12981298
(Contributed by Alex Waygood in :gh:`91896`.)
12991299

‎Doc/whatsnew/3.13.rst

Copy file name to clipboardExpand all lines: Doc/whatsnew/3.13.rst
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,7 @@ Pending Removal in Python 3.14
15731573
Use :class:`ast.Constant` instead.
15741574
(Contributed by Serhiy Storchaka in :gh:`90953`.)
15751575

1576-
* :mod:`collections.abc`: Deprecated :class:`~collections.abc.ByteString`.
1576+
* :mod:`collections.abc`: Deprecated :class:`!collections.abc.ByteString`.
15771577
Prefer :class:`!Sequence` or :class:`~collections.abc.Buffer`.
15781578
For use in typing, prefer a union, like ``bytes | bytearray``,
15791579
or :class:`collections.abc.Buffer`.
@@ -1647,7 +1647,7 @@ Pending Removal in Python 3.14
16471647
May be removed in 3.14.
16481648
(Contributed by Nikita Sobolev in :gh:`101866`.)
16491649

1650-
* :mod:`typing`: :class:`~typing.ByteString`, deprecated since Python 3.9,
1650+
* :mod:`typing`: :class:`!typing.ByteString`, deprecated since Python 3.9,
16511651
now causes a :exc:`DeprecationWarning` to be emitted when it is used.
16521652

16531653
* :mod:`urllib`:

‎Doc/whatsnew/3.14.rst

Copy file name to clipboardExpand all lines: Doc/whatsnew/3.14.rst
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ Removed
105105
It had previously raised a :exc:`DeprecationWarning` since Python 3.9. (Contributed
106106
by Jelle Zijlstra in :gh:`118767`.)
107107

108+
* :class:`!typing.ByteString` and :class:`!collections.abc.ByteString`
109+
are removed. They had previously raised a :exc:`DeprecationWarning`
110+
since Python 3.12.
108111

109112
Porting to Python 3.14
110113
======================

‎Lib/_collections_abc.py

Copy file name to clipboardExpand all lines: Lib/_collections_abc.py
+3-33Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _f(): pass
4949
"Mapping", "MutableMapping",
5050
"MappingView", "KeysView", "ItemsView", "ValuesView",
5151
"Sequence", "MutableSequence",
52-
"ByteString", "Buffer",
52+
"Buffer",
5353
]
5454

5555
# This module has been renamed from collections.abc to _collections_abc to
@@ -1068,40 +1068,10 @@ def count(self, value):
10681068

10691069
Sequence.register(tuple)
10701070
Sequence.register(str)
1071+
Sequence.register(bytes)
10711072
Sequence.register(range)
10721073
Sequence.register(memoryview)
10731074

1074-
class _DeprecateByteStringMeta(ABCMeta):
1075-
def __new__(cls, name, bases, namespace, **kwargs):
1076-
if name != "ByteString":
1077-
import warnings
1078-
1079-
warnings._deprecated(
1080-
"collections.abc.ByteString",
1081-
remove=(3, 14),
1082-
)
1083-
return super().__new__(cls, name, bases, namespace, **kwargs)
1084-
1085-
def __instancecheck__(cls, instance):
1086-
import warnings
1087-
1088-
warnings._deprecated(
1089-
"collections.abc.ByteString",
1090-
remove=(3, 14),
1091-
)
1092-
return super().__instancecheck__(instance)
1093-
1094-
class ByteString(Sequence, metaclass=_DeprecateByteStringMeta):
1095-
"""This unifies bytes and bytearray.
1096-
1097-
XXX Should add all their methods.
1098-
"""
1099-
1100-
__slots__ = ()
1101-
1102-
ByteString.register(bytes)
1103-
ByteString.register(bytearray)
1104-
11051075

11061076
class MutableSequence(Sequence):
11071077
"""All the operations on a read-write sequence.
@@ -1170,4 +1140,4 @@ def __iadd__(self, values):
11701140

11711141

11721142
MutableSequence.register(list)
1173-
MutableSequence.register(bytearray) # Multiply inheriting, see ByteString
1143+
MutableSequence.register(bytearray)

‎Lib/test/libregrtest/refleak.py

Copy file name to clipboardExpand all lines: Lib/test/libregrtest/refleak.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ def dash_R_cleanup(fs, ps, pic, zdc, abcs):
211211
zipimport._zip_directory_cache.update(zdc)
212212

213213
# Clear ABC registries, restoring previously saved ABC registries.
214-
# ignore deprecation warning for collections.abc.ByteString
215214
abs_classes = [getattr(collections.abc, a) for a in collections.abc.__all__]
216215
abs_classes = filter(isabstract, abs_classes)
217216
for abc in abs_classes:

‎Lib/test/test_collections.py

Copy file name to clipboardExpand all lines: Lib/test/test_collections.py
+1-23Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from collections.abc import Set, MutableSet
2727
from collections.abc import Mapping, MutableMapping, KeysView, ItemsView, ValuesView
2828
from collections.abc import Sequence, MutableSequence
29-
from collections.abc import ByteString, Buffer
29+
from collections.abc import Buffer
3030

3131

3232
class TestUserObjects(unittest.TestCase):
@@ -1935,28 +1935,6 @@ def assert_index_same(seq1, seq2, index_args):
19351935
assert_index_same(
19361936
nativeseq, seqseq, (letter, start, stop))
19371937

1938-
def test_ByteString(self):
1939-
for sample in [bytes, bytearray]:
1940-
with self.assertWarns(DeprecationWarning):
1941-
self.assertIsInstance(sample(), ByteString)
1942-
self.assertTrue(issubclass(sample, ByteString))
1943-
for sample in [str, list, tuple]:
1944-
with self.assertWarns(DeprecationWarning):
1945-
self.assertNotIsInstance(sample(), ByteString)
1946-
self.assertFalse(issubclass(sample, ByteString))
1947-
with self.assertWarns(DeprecationWarning):
1948-
self.assertNotIsInstance(memoryview(b""), ByteString)
1949-
self.assertFalse(issubclass(memoryview, ByteString))
1950-
with self.assertWarns(DeprecationWarning):
1951-
self.validate_abstract_methods(ByteString, '__getitem__', '__len__')
1952-
1953-
with self.assertWarns(DeprecationWarning):
1954-
class X(ByteString): pass
1955-
1956-
with self.assertWarns(DeprecationWarning):
1957-
# No metaclass conflict
1958-
class Z(ByteString, Awaitable): pass
1959-
19601938
def test_Buffer(self):
19611939
for sample in [bytes, bytearray, memoryview]:
19621940
self.assertIsInstance(sample(b"x"), Buffer)

‎Lib/test/test_typing.py

Copy file name to clipboardExpand all lines: Lib/test/test_typing.py
-11Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7128,16 +7128,6 @@ def test_mutablesequence(self):
71287128
self.assertIsInstance([], typing.MutableSequence)
71297129
self.assertNotIsInstance((), typing.MutableSequence)
71307130

7131-
def test_bytestring(self):
7132-
with self.assertWarns(DeprecationWarning):
7133-
self.assertIsInstance(b'', typing.ByteString)
7134-
with self.assertWarns(DeprecationWarning):
7135-
self.assertIsInstance(bytearray(b''), typing.ByteString)
7136-
with self.assertWarns(DeprecationWarning):
7137-
class Foo(typing.ByteString): ...
7138-
with self.assertWarns(DeprecationWarning):
7139-
class Bar(typing.ByteString, typing.Awaitable): ...
7140-
71417131
def test_list(self):
71427132
self.assertIsSubclass(list, typing.List)
71437133

@@ -9951,7 +9941,6 @@ def test_special_attrs(self):
99519941
typing.AsyncIterable: 'AsyncIterable',
99529942
typing.AsyncIterator: 'AsyncIterator',
99539943
typing.Awaitable: 'Awaitable',
9954-
typing.ByteString: 'ByteString',
99559944
typing.Callable: 'Callable',
99569945
typing.ChainMap: 'ChainMap',
99579946
typing.Collection: 'Collection',

‎Lib/typing.py

Copy file name to clipboardExpand all lines: Lib/typing.py
-19Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464

6565
# ABCs (from collections.abc).
6666
'AbstractSet', # collections.abc.Set.
67-
'ByteString',
6867
'Container',
6968
'ContextManager',
7069
'Hashable',
@@ -1670,21 +1669,6 @@ def __ror__(self, left):
16701669
return Union[left, self]
16711670

16721671

1673-
class _DeprecatedGenericAlias(_SpecialGenericAlias, _root=True):
1674-
def __init__(
1675-
self, origin, nparams, *, removal_version, inst=True, name=None
1676-
):
1677-
super().__init__(origin, nparams, inst=inst, name=name)
1678-
self._removal_version = removal_version
1679-
1680-
def __instancecheck__(self, inst):
1681-
import warnings
1682-
warnings._deprecated(
1683-
f"{self.__module__}.{self._name}", remove=self._removal_version
1684-
)
1685-
return super().__instancecheck__(inst)
1686-
1687-
16881672
class _CallableGenericAlias(_NotIterable, _GenericAlias, _root=True):
16891673
def __repr__(self):
16901674
assert self._name == 'Callable'
@@ -2828,9 +2812,6 @@ class Other(Leaf): # Error reported by type checker
28282812
MutableMapping = _alias(collections.abc.MutableMapping, 2)
28292813
Sequence = _alias(collections.abc.Sequence, 1)
28302814
MutableSequence = _alias(collections.abc.MutableSequence, 1)
2831-
ByteString = _DeprecatedGenericAlias(
2832-
collections.abc.ByteString, 0, removal_version=(3, 14) # Not generic.
2833-
)
28342815
# Tuple accepts variable number of parameters.
28352816
Tuple = _TupleType(tuple, -1, inst=False, name='Tuple')
28362817
Tuple.__doc__ = \
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:class:`!typing.ByteString` and :class:`!collections.abc.ByteString` are
2+
removed. They had previously raised a :exc:`DeprecationWarning` since Python
3+
3.12.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.