]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-118803: Remove `ByteString` from `typing` and `collections.abc` (#118804)
authorNikita Sobolev <mail@sobolevn.me>
Wed, 8 May 2024 23:37:55 +0000 (02:37 +0300)
committerGitHub <noreply@github.com>
Wed, 8 May 2024 23:37:55 +0000 (00:37 +0100)
12 files changed:
Doc/library/collections.abc.rst
Doc/library/stdtypes.rst
Doc/library/typing.rst
Doc/whatsnew/3.12.rst
Doc/whatsnew/3.13.rst
Doc/whatsnew/3.14.rst
Lib/_collections_abc.py
Lib/test/libregrtest/refleak.py
Lib/test/test_collections.py
Lib/test/test_typing.py
Lib/typing.py
Misc/NEWS.d/next/Library/2024-05-09-00-52-30.gh-issue-118803.Wv3AvU.rst [new file with mode: 0644]

index ea27436f67f0bfe1d6a73bb9287f852ad1e50795..a63a55caa0f66d72062c701fd55ea9b27c8bff40 100644 (file)
@@ -141,9 +141,6 @@ ABC                            Inherits from          Abstract Methods        Mi
                                                       ``__len__``,
                                                       ``insert``
 
-:class:`ByteString`            :class:`Sequence`      ``__getitem__``,        Inherited :class:`Sequence` methods
-                                                      ``__len__``
-
 :class:`Set`                   :class:`Collection`    ``__contains__``,       ``__le__``, ``__lt__``, ``__eq__``, ``__ne__``,
                                                       ``__iter__``,           ``__gt__``, ``__ge__``, ``__and__``, ``__or__``,
                                                       ``__len__``             ``__sub__``, ``__xor__``, and ``isdisjoint``
@@ -257,7 +254,6 @@ Collections Abstract Base Classes -- Detailed Descriptions
 
 .. class:: Sequence
            MutableSequence
-           ByteString
 
    ABCs for read-only and mutable :term:`sequences <sequence>`.
 
@@ -274,12 +270,6 @@ Collections Abstract Base Classes -- Detailed Descriptions
       The index() method added support for *stop* and *start*
       arguments.
 
-   .. deprecated-removed:: 3.12 3.14
-      The :class:`ByteString` ABC has been deprecated.
-      For use in typing, prefer a union, like ``bytes | bytearray``, or
-      :class:`collections.abc.Buffer`.
-      For use as an ABC, prefer :class:`Sequence` or :class:`collections.abc.Buffer`.
-
 .. class:: Set
            MutableSet
 
index 8f5f9ee519a5739aa8fc4fd9e7f901849c816198..f97597dc56544991903eb571f36a47ceaed0305c 100644 (file)
@@ -5061,7 +5061,6 @@ list is non-exhaustive.
 * :class:`collections.abc.MutableMapping`
 * :class:`collections.abc.Sequence`
 * :class:`collections.abc.MutableSequence`
-* :class:`collections.abc.ByteString`
 * :class:`collections.abc.MappingView`
 * :class:`collections.abc.KeysView`
 * :class:`collections.abc.ItemsView`
index 812589a3920ecd5881a02e47c661a0f91f03b71a..5b74dd9c9f4914bc4d50df1b89d3e3d3e3238fb5 100644 (file)
@@ -3502,14 +3502,6 @@ Aliases to container ABCs in :mod:`collections.abc`
       :class:`collections.abc.Set` now supports subscripting (``[]``).
       See :pep:`585` and :ref:`types-genericalias`.
 
-.. class:: ByteString(Sequence[int])
-
-   This type represents the types :class:`bytes`, :class:`bytearray`,
-   and :class:`memoryview` of byte sequences.
-
-   .. deprecated-removed:: 3.9 3.14
-      Prefer :class:`collections.abc.Buffer`, or a union like ``bytes | bytearray | memoryview``.
-
 .. class:: Collection(Sized, Iterable[T_co], Container[T_co])
 
    Deprecated alias to :class:`collections.abc.Collection`.
@@ -3875,10 +3867,6 @@ convenience. This is subject to change, and not all deprecations are listed.
      - 3.9
      - Undecided (see :ref:`deprecated-aliases` for more information)
      - :pep:`585`
-   * - :class:`typing.ByteString`
-     - 3.9
-     - 3.14
-     - :gh:`91896`
    * - :data:`typing.Text`
      - 3.11
      - Undecided
index 8757311a484257dd5905df5f879678a3056a750e..685d0120f2f63670e31b66781a8307dda81dcf5f 100644 (file)
@@ -1183,7 +1183,7 @@ Deprecated
   replaced by :data:`calendar.JANUARY` and :data:`calendar.FEBRUARY`.
   (Contributed by Prince Roshan in :gh:`103636`.)
 
-* :mod:`collections.abc`: Deprecated :class:`collections.abc.ByteString`.
+* :mod:`collections.abc`: Deprecated :class:`!collections.abc.ByteString`.
   Prefer :class:`Sequence` or :class:`collections.abc.Buffer`.
   For use in typing, prefer a union, like ``bytes | bytearray``, or :class:`collections.abc.Buffer`.
   (Contributed by Shantanu Jain in :gh:`91896`.)
@@ -1293,7 +1293,7 @@ Deprecated
     :class:`collections.abc.Hashable` and :class:`collections.abc.Sized` respectively, are
     deprecated. (:gh:`94309`.)
 
-  * :class:`typing.ByteString`, deprecated since Python 3.9, now causes a
+  * :class:`!typing.ByteString`, deprecated since Python 3.9, now causes a
     :exc:`DeprecationWarning` to be emitted when it is used.
     (Contributed by Alex Waygood in :gh:`91896`.)
 
index 8e90faee667dede73f71bcf7bb5ac73ef2b7d663..44555718184e19cf590d3e4e6aee2b1603815c16 100644 (file)
@@ -1573,7 +1573,7 @@ Pending Removal in Python 3.14
   Use :class:`ast.Constant` instead.
   (Contributed by Serhiy Storchaka in :gh:`90953`.)
 
-* :mod:`collections.abc`: Deprecated :class:`~collections.abc.ByteString`.
+* :mod:`collections.abc`: Deprecated :class:`!collections.abc.ByteString`.
   Prefer :class:`!Sequence` or :class:`~collections.abc.Buffer`.
   For use in typing, prefer a union, like ``bytes | bytearray``,
   or :class:`collections.abc.Buffer`.
@@ -1647,7 +1647,7 @@ Pending Removal in Python 3.14
   May be removed in 3.14.
   (Contributed by Nikita Sobolev in :gh:`101866`.)
 
-* :mod:`typing`: :class:`~typing.ByteString`, deprecated since Python 3.9,
+* :mod:`typing`: :class:`!typing.ByteString`, deprecated since Python 3.9,
   now causes a :exc:`DeprecationWarning` to be emitted when it is used.
 
 * :mod:`urllib`:
index 6a9d0b0d912fb26b935cfc51a6716569cf9098e6..5aa6e4f7a9ed3e867827116eb8678bfe0bb39286 100644 (file)
@@ -105,6 +105,9 @@ Removed
   It had previously raised a :exc:`DeprecationWarning` since Python 3.9. (Contributed
   by Jelle Zijlstra in :gh:`118767`.)
 
+* :class:`!typing.ByteString` and :class:`!collections.abc.ByteString`
+  are removed. They had previously raised a :exc:`DeprecationWarning`
+  since Python 3.12.
 
 Porting to Python 3.14
 ======================
index 601107d2d867718fb3dd44f409a3db07edc515bd..1135e17e3790590058dc2aaa70d50f0eea8a01d3 100644 (file)
@@ -49,7 +49,7 @@ __all__ = ["Awaitable", "Coroutine",
            "Mapping", "MutableMapping",
            "MappingView", "KeysView", "ItemsView", "ValuesView",
            "Sequence", "MutableSequence",
-           "ByteString", "Buffer",
+           "Buffer",
            ]
 
 # This module has been renamed from collections.abc to _collections_abc to
@@ -1068,40 +1068,10 @@ class Sequence(Reversible, Collection):
 
 Sequence.register(tuple)
 Sequence.register(str)
+Sequence.register(bytes)
 Sequence.register(range)
 Sequence.register(memoryview)
 
-class _DeprecateByteStringMeta(ABCMeta):
-    def __new__(cls, name, bases, namespace, **kwargs):
-        if name != "ByteString":
-            import warnings
-
-            warnings._deprecated(
-                "collections.abc.ByteString",
-                remove=(3, 14),
-            )
-        return super().__new__(cls, name, bases, namespace, **kwargs)
-
-    def __instancecheck__(cls, instance):
-        import warnings
-
-        warnings._deprecated(
-            "collections.abc.ByteString",
-            remove=(3, 14),
-        )
-        return super().__instancecheck__(instance)
-
-class ByteString(Sequence, metaclass=_DeprecateByteStringMeta):
-    """This unifies bytes and bytearray.
-
-    XXX Should add all their methods.
-    """
-
-    __slots__ = ()
-
-ByteString.register(bytes)
-ByteString.register(bytearray)
-
 
 class MutableSequence(Sequence):
     """All the operations on a read-write sequence.
@@ -1170,4 +1140,4 @@ class MutableSequence(Sequence):
 
 
 MutableSequence.register(list)
-MutableSequence.register(bytearray)  # Multiply inheriting, see ByteString
+MutableSequence.register(bytearray)
index f582c0d3e7ff1345692f80c9734f396f978c4d3a..bb57ffd75636cb3d5d3407fa8438e9b5b89ec4d2 100644 (file)
@@ -211,7 +211,6 @@ def dash_R_cleanup(fs, ps, pic, zdc, abcs):
         zipimport._zip_directory_cache.update(zdc)
 
     # Clear ABC registries, restoring previously saved ABC registries.
-    # ignore deprecation warning for collections.abc.ByteString
     abs_classes = [getattr(collections.abc, a) for a in collections.abc.__all__]
     abs_classes = filter(isabstract, abs_classes)
     for abc in abs_classes:
index 955323cae88f922a49985af6b0b611a43c8b5d0a..a24d3e3ea142b7fa1001e26c6463f5b403251205 100644 (file)
@@ -26,7 +26,7 @@ from collections.abc import Sized, Container, Callable, Collection
 from collections.abc import Set, MutableSet
 from collections.abc import Mapping, MutableMapping, KeysView, ItemsView, ValuesView
 from collections.abc import Sequence, MutableSequence
-from collections.abc import ByteString, Buffer
+from collections.abc import Buffer
 
 
 class TestUserObjects(unittest.TestCase):
@@ -1935,28 +1935,6 @@ class TestCollectionABCs(ABCTestCase):
                         assert_index_same(
                             nativeseq, seqseq, (letter, start, stop))
 
-    def test_ByteString(self):
-        for sample in [bytes, bytearray]:
-            with self.assertWarns(DeprecationWarning):
-                self.assertIsInstance(sample(), ByteString)
-            self.assertTrue(issubclass(sample, ByteString))
-        for sample in [str, list, tuple]:
-            with self.assertWarns(DeprecationWarning):
-                self.assertNotIsInstance(sample(), ByteString)
-            self.assertFalse(issubclass(sample, ByteString))
-        with self.assertWarns(DeprecationWarning):
-            self.assertNotIsInstance(memoryview(b""), ByteString)
-        self.assertFalse(issubclass(memoryview, ByteString))
-        with self.assertWarns(DeprecationWarning):
-            self.validate_abstract_methods(ByteString, '__getitem__', '__len__')
-
-        with self.assertWarns(DeprecationWarning):
-            class X(ByteString): pass
-
-        with self.assertWarns(DeprecationWarning):
-            # No metaclass conflict
-            class Z(ByteString, Awaitable): pass
-
     def test_Buffer(self):
         for sample in [bytes, bytearray, memoryview]:
             self.assertIsInstance(sample(b"x"), Buffer)
index fff81f7997764d585b9d203ce5c05e3163746e2d..8dde8aedd2a2b164b8bd8543e0fd701d17ec3427 100644 (file)
@@ -7128,16 +7128,6 @@ class CollectionsAbcTests(BaseTestCase):
         self.assertIsInstance([], typing.MutableSequence)
         self.assertNotIsInstance((), typing.MutableSequence)
 
-    def test_bytestring(self):
-        with self.assertWarns(DeprecationWarning):
-            self.assertIsInstance(b'', typing.ByteString)
-        with self.assertWarns(DeprecationWarning):
-            self.assertIsInstance(bytearray(b''), typing.ByteString)
-        with self.assertWarns(DeprecationWarning):
-            class Foo(typing.ByteString): ...
-        with self.assertWarns(DeprecationWarning):
-            class Bar(typing.ByteString, typing.Awaitable): ...
-
     def test_list(self):
         self.assertIsSubclass(list, typing.List)
 
@@ -9951,7 +9941,6 @@ class SpecialAttrsTests(BaseTestCase):
             typing.AsyncIterable: 'AsyncIterable',
             typing.AsyncIterator: 'AsyncIterator',
             typing.Awaitable: 'Awaitable',
-            typing.ByteString: 'ByteString',
             typing.Callable: 'Callable',
             typing.ChainMap: 'ChainMap',
             typing.Collection: 'Collection',
index c8649e312ddb000f0e565c8d64e834231ac3c9e7..e75a627d226e5055e78cf52503d0dc4e65df6709 100644 (file)
@@ -64,7 +64,6 @@ __all__ = [
 
     # ABCs (from collections.abc).
     'AbstractSet',  # collections.abc.Set.
-    'ByteString',
     'Container',
     'ContextManager',
     'Hashable',
@@ -1670,21 +1669,6 @@ class _SpecialGenericAlias(_NotIterable, _BaseGenericAlias, _root=True):
         return Union[left, self]
 
 
-class _DeprecatedGenericAlias(_SpecialGenericAlias, _root=True):
-    def __init__(
-        self, origin, nparams, *, removal_version, inst=True, name=None
-    ):
-        super().__init__(origin, nparams, inst=inst, name=name)
-        self._removal_version = removal_version
-
-    def __instancecheck__(self, inst):
-        import warnings
-        warnings._deprecated(
-            f"{self.__module__}.{self._name}", remove=self._removal_version
-        )
-        return super().__instancecheck__(inst)
-
-
 class _CallableGenericAlias(_NotIterable, _GenericAlias, _root=True):
     def __repr__(self):
         assert self._name == 'Callable'
@@ -2828,9 +2812,6 @@ Mapping = _alias(collections.abc.Mapping, 2)
 MutableMapping = _alias(collections.abc.MutableMapping, 2)
 Sequence = _alias(collections.abc.Sequence, 1)
 MutableSequence = _alias(collections.abc.MutableSequence, 1)
-ByteString = _DeprecatedGenericAlias(
-    collections.abc.ByteString, 0, removal_version=(3, 14)  # Not generic.
-)
 # Tuple accepts variable number of parameters.
 Tuple = _TupleType(tuple, -1, inst=False, name='Tuple')
 Tuple.__doc__ = \
diff --git a/Misc/NEWS.d/next/Library/2024-05-09-00-52-30.gh-issue-118803.Wv3AvU.rst b/Misc/NEWS.d/next/Library/2024-05-09-00-52-30.gh-issue-118803.Wv3AvU.rst
new file mode 100644 (file)
index 0000000..2d86dff
--- /dev/null
@@ -0,0 +1,3 @@
+:class:`!typing.ByteString` and :class:`!collections.abc.ByteString` are
+removed. They had previously raised a :exc:`DeprecationWarning` since Python
+3.12.