@@ -5,14 +5,23 @@ Pending removal in Python 3.17
55
66 - :class: `collections.abc.ByteString ` is scheduled for removal in Python 3.17.
77
8- ``ByteString `` was originally intended to be an abstract type that would serve as a
9- supertype of both :class: `bytes ` and :class: `bytearray `, but its semantics were never
10- clearly specified, and it was never understood properly by type checkers. See
11- :pep: `PEP 688 <688#current-options >` for more details.
8+ Use ``isinstance(obj, collections.abc.Buffer) `` to test if ``obj ``
9+ implements the :ref: `buffer protocol <bufferobjects >` at runtime. For use
10+ in type annotations, either use :class: `Buffer ` or a union that explicitly
11+ specifies the types your code supports (e.g.,
12+ ``bytes | bytearray | memoryview ``).
13+
14+ :class: `!ByteString ` was originally intended to be an abstract class that
15+ would serve as a supertype of both :class: `bytes ` and :class: `bytearray `.
16+ However, since the ABC never had any methods, knowing that an object was an
17+ instance of :class: `!ByteString ` never actually told you anything useful
18+ about the object. Other common buffer types such as :class: `memoryview `
19+ were also never understood as subtypes of :class: `!ByteString ` (either at
20+ runtime or by static type checkers).
21+
22+ See :pep: `PEP 688 <688#current-options >` for more details.
23+ (Contributed by Shantanu Jain in :gh: `91896 `.)
1224
13- Prefer :class: `~collections.abc.Sequence ` or :class: `~collections.abc.Buffer `. For
14- use in type annotations, prefer a union, like ``bytes | bytearray ``, or
15- :class: `collections.abc.Buffer `. (Contributed by Shantanu Jain in :gh: `91896 `.)
1625
1726* :mod: `typing `:
1827
@@ -24,12 +33,19 @@ Pending removal in Python 3.17
2433 - :class: `typing.ByteString `, deprecated since Python 3.9, is scheduled for removal in
2534 Python 3.17.
2635
27- ``ByteString `` was originally intended to be an abstract type that would serve as a
28- supertype of both :class: `bytes ` and :class: `bytearray `, but its semantics were never
29- clearly specified, and it was never understood properly by type checkers. See
30- :pep: `PEP 688 <688#current-options >` for more details.
31-
32- Prefer :class: `~collections.abc.Sequence ` or :class: `~collections.abc.Buffer `. For
33- use in type annotations, prefer a union, like ``bytes | bytearray ``, or
34- :class: `collections.abc.Buffer `.
36+ Use ``isinstance(obj, collections.abc.Buffer) `` to test if ``obj ``
37+ implements the :ref: `buffer protocol <bufferobjects >` at runtime. For use
38+ in type annotations, either use :class: `~collections.abc.Buffer ` or a union
39+ that explicitly specifies the types your code supports (e.g.,
40+ ``bytes | bytearray | memoryview ``).
41+
42+ :class: `!ByteString ` was originally intended to be an abstract class that
43+ would serve as a supertype of both :class: `bytes ` and :class: `bytearray `.
44+ However, since the ABC never had any methods, knowing that an object was an
45+ instance of :class: `!ByteString ` never actually told you anything useful
46+ about the object. Other common buffer types such as :class: `memoryview `
47+ were also never understood as subtypes of :class: `!ByteString ` (either at
48+ runtime or by static type checkers).
49+
50+ See :pep: `PEP 688 <688#current-options >` for more details.
3551 (Contributed by Shantanu Jain in :gh: `91896 `.)
0 commit comments