gh-118803: Remove ByteString from typing and collections.abc (#118804)

This commit is contained in:
Nikita Sobolev 2024-05-09 02:37:55 +03:00 committed by GitHub
parent cb6f75a32c
commit 2f4db5a04d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 14 additions and 114 deletions

View 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)