``__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``
.. class:: Sequence
MutableSequence
- ByteString
ABCs for read-only and mutable :term:`sequences <sequence>`.
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
* :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`
: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`.
- 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
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`.)
: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`.)
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`.
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`:
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
======================
"Mapping", "MutableMapping",
"MappingView", "KeysView", "ItemsView", "ValuesView",
"Sequence", "MutableSequence",
- "ByteString", "Buffer",
+ "Buffer",
]
# This module has been renamed from collections.abc to _collections_abc to
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.
MutableSequence.register(list)
-MutableSequence.register(bytearray) # Multiply inheriting, see ByteString
+MutableSequence.register(bytearray)
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:
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):
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)
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)
typing.AsyncIterable: 'AsyncIterable',
typing.AsyncIterator: 'AsyncIterator',
typing.Awaitable: 'Awaitable',
- typing.ByteString: 'ByteString',
typing.Callable: 'Callable',
typing.ChainMap: 'ChainMap',
typing.Collection: 'Collection',
# ABCs (from collections.abc).
'AbstractSet', # collections.abc.Set.
- 'ByteString',
'Container',
'ContextManager',
'Hashable',
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'
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__ = \
--- /dev/null
+:class:`!typing.ByteString` and :class:`!collections.abc.ByteString` are
+removed. They had previously raised a :exc:`DeprecationWarning` since Python
+3.12.