Skip to content

Commit e730b34

Browse files
authored
Merge branch 'main' into jit-rosetta-x86
2 parents 30e800a + 85c1ef6 commit e730b34

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4254
-1184
lines changed
Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
Pending removal in Python 3.17
22
------------------------------
33

4+
* :mod:`collections.abc`:
5+
6+
- :class:`collections.abc.ByteString` is scheduled for removal in Python 3.17.
7+
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:`~collections.abc.Buffer` or a union
11+
that explicitly 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`.)
24+
25+
426
* :mod:`typing`:
527

628
- Before Python 3.14, old-style unions were implemented using the private class
@@ -9,14 +31,21 @@ Pending removal in Python 3.17
931
3.17. Users should use documented introspection helpers like :func:`typing.get_origin`
1032
and :func:`typing.get_args` instead of relying on private implementation details.
1133
- :class:`typing.ByteString`, deprecated since Python 3.9, is scheduled for removal in
12-
Python 3.17. Prefer :class:`~collections.abc.Sequence` or
13-
:class:`~collections.abc.Buffer`. For use in type annotations, prefer a union, like
14-
``bytes | bytearray``, or :class:`collections.abc.Buffer`.
15-
(Contributed by Shantanu Jain in :gh:`91896`.)
34+
Python 3.17.
1635

17-
* :mod:`collections.abc`:
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).
1849

19-
- :class:`collections.abc.ByteString` is scheduled for removal in Python 3.17. Prefer
20-
:class:`~collections.abc.Sequence` or :class:`~collections.abc.Buffer`. For use in
21-
type annotations, prefer a union, like ``bytes | bytearray``, or
22-
:class:`collections.abc.Buffer`. (Contributed by Shantanu Jain in :gh:`91896`.)
50+
See :pep:`PEP 688 <688#current-options>` for more details.
51+
(Contributed by Shantanu Jain in :gh:`91896`.)

Doc/library/collections.abc.rst

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,22 @@ Collections Abstract Base Classes -- Detailed Descriptions
291291

292292
.. deprecated-removed:: 3.12 3.17
293293
The :class:`ByteString` ABC has been deprecated.
294-
For use in type annotations, prefer a union, like ``bytes | bytearray``, or
295-
:class:`collections.abc.Buffer`.
296-
For use as an ABC, prefer :class:`Sequence` or :class:`collections.abc.Buffer`.
294+
295+
Use ``isinstance(obj, collections.abc.Buffer)`` to test if ``obj``
296+
implements the :ref:`buffer protocol <bufferobjects>` at runtime. For use
297+
in type annotations, either use :class:`Buffer` or a union that
298+
explicitly specifies the types your code supports (e.g.,
299+
``bytes | bytearray | memoryview``).
300+
301+
:class:`!ByteString` was originally intended to be an abstract class that
302+
would serve as a supertype of both :class:`bytes` and :class:`bytearray`.
303+
However, since the ABC never had any methods, knowing that an object was
304+
an instance of :class:`!ByteString` never actually told you anything
305+
useful about the object. Other common buffer types such as
306+
:class:`memoryview` were also never understood as subtypes of
307+
:class:`!ByteString` (either at runtime or by static type checkers).
308+
309+
See :pep:`PEP 688 <688#current-options>` for more details.
297310

298311
.. class:: Set
299312
MutableSet

Doc/library/datetime.rst

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,7 +2629,10 @@ differences between platforms in handling of unsupported format specifiers.
26292629
``%G``, ``%u`` and ``%V`` were added.
26302630

26312631
.. versionadded:: 3.12
2632-
``%:z`` was added.
2632+
``%:z`` was added for :meth:`~.datetime.strftime`
2633+
2634+
.. versionadded:: next
2635+
``%:z`` was added for :meth:`~.datetime.strptime`
26332636

26342637
Technical Detail
26352638
^^^^^^^^^^^^^^^^
@@ -2724,12 +2727,18 @@ Notes:
27242727
When the ``%z`` directive is provided to the :meth:`~.datetime.strptime` method,
27252728
the UTC offsets can have a colon as a separator between hours, minutes
27262729
and seconds.
2727-
For example, ``'+01:00:00'`` will be parsed as an offset of one hour.
2728-
In addition, providing ``'Z'`` is identical to ``'+00:00'``.
2730+
For example, both ``'+010000'`` and ``'+01:00:00'`` will be parsed as an offset
2731+
of one hour. In addition, providing ``'Z'`` is identical to ``'+00:00'``.
27292732

27302733
``%:z``
2731-
Behaves exactly as ``%z``, but has a colon separator added between
2732-
hours, minutes and seconds.
2734+
When used with :meth:`~.datetime.strftime`, behaves exactly as ``%z``,
2735+
except that a colon separator is added between hours, minutes and seconds.
2736+
2737+
When used with :meth:`~.datetime.strptime`, the UTC offset is *required*
2738+
to have a colon as a separator between hours, minutes and seconds.
2739+
For example, ``'+01:00:00'`` (but *not* ``'+010000'``) will be parsed as
2740+
an offset of one hour. In addition, providing ``'Z'`` is identical to
2741+
``'+00:00'``.
27332742

27342743
``%Z``
27352744
In :meth:`~.datetime.strftime`, ``%Z`` is replaced by an empty string if

Doc/library/os.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,7 @@ or `the MSDN <https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Windo
15011501

15021502
- :data:`RWF_HIPRI`
15031503
- :data:`RWF_NOWAIT`
1504+
- :data:`RWF_DONTCACHE`
15041505

15051506
Return the total number of bytes actually read which can be less than the
15061507
total capacity of all the objects.
@@ -1546,6 +1547,15 @@ or `the MSDN <https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Windo
15461547
.. versionadded:: 3.7
15471548

15481549

1550+
.. data:: RWF_DONTCACHE
1551+
1552+
Use uncached buffered IO.
1553+
1554+
.. availability:: Linux >= 6.14
1555+
1556+
.. versionadded:: next
1557+
1558+
15491559
.. function:: ptsname(fd, /)
15501560

15511561
Return the name of the slave pseudo-terminal device associated with the
@@ -1587,6 +1597,7 @@ or `the MSDN <https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Windo
15871597
- :data:`RWF_DSYNC`
15881598
- :data:`RWF_SYNC`
15891599
- :data:`RWF_APPEND`
1600+
- :data:`RWF_DONTCACHE`
15901601

15911602
Return the total number of bytes actually written.
15921603

Doc/library/typing.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3790,11 +3790,25 @@ Aliases to container ABCs in :mod:`collections.abc`
37903790

37913791
.. class:: ByteString(Sequence[int])
37923792

3793-
This type represents the types :class:`bytes`, :class:`bytearray`,
3794-
and :class:`memoryview` of byte sequences.
3793+
Deprecated alias to :class:`collections.abc.ByteString`.
3794+
3795+
Use ``isinstance(obj, collections.abc.Buffer)`` to test if ``obj``
3796+
implements the :ref:`buffer protocol <bufferobjects>` at runtime. For use in
3797+
type annotations, either use :class:`~collections.abc.Buffer` or a union
3798+
that explicitly specifies the types your code supports (e.g.,
3799+
``bytes | bytearray | memoryview``).
3800+
3801+
:class:`!ByteString` was originally intended to be an abstract class that
3802+
would serve as a supertype of both :class:`bytes` and :class:`bytearray`.
3803+
However, since the ABC never had any methods, knowing that an object was an
3804+
instance of :class:`!ByteString` never actually told you anything useful
3805+
about the object. Other common buffer types such as :class:`memoryview` were
3806+
also never understood as subtypes of :class:`!ByteString` (either at runtime
3807+
or by static type checkers).
3808+
3809+
See :pep:`PEP 688 <688#current-options>` for more details.
37953810

37963811
.. deprecated-removed:: 3.9 3.17
3797-
Prefer :class:`collections.abc.Buffer`, or a union like ``bytes | bytearray | memoryview``.
37983812

37993813
.. class:: Collection(Sized, Iterable[T_co], Container[T_co])
38003814

Doc/library/zoneinfo.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ Functions
349349

350350
This function only includes canonical zone names and does not include
351351
"special" zones such as those under the ``posix/`` and ``right/``
352-
directories, or the ``posixrules`` zone.
352+
directories, the ``posixrules`` or the ``localtime`` zone.
353353

354354
.. caution::
355355

Doc/using/android.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,15 @@ If you're sure you want to do all of this manually, read on. You can use the
4040
:source:`testbed app <Android/testbed>` as a guide; each step below contains a
4141
link to the relevant file.
4242

43-
* Build Python by following the instructions in :source:`Android/README.md`.
44-
This will create the directory ``cross-build/HOST/prefix``.
43+
* First, acquire a build of Python for Android:
44+
45+
* The easiest way is to download an Android release from `python.org
46+
<https://www.python.org/downloads/android/>`__. The ``prefix`` directory
47+
mentioned below is at the top level of the package.
48+
49+
* Or if you want to build it yourself, follow the instructions in
50+
:source:`Android/README.md`. The ``prefix`` directory will be created under
51+
:samp:`cross-build/{HOST}`.
4552

4653
* Add code to your :source:`build.gradle <Android/testbed/app/build.gradle.kts>`
4754
file to copy the following items into your project. All except your own Python

Doc/whatsnew/3.12.rst

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,8 +1192,22 @@ Deprecated
11921192
(Contributed by Prince Roshan in :gh:`103636`.)
11931193

11941194
* :mod:`collections.abc`: Deprecated :class:`collections.abc.ByteString`.
1195-
Prefer :class:`Sequence` or :class:`collections.abc.Buffer`.
1196-
For use in type annotations, prefer a union, like ``bytes | bytearray``, or :class:`collections.abc.Buffer`.
1195+
1196+
Use ``isinstance(obj, collections.abc.Buffer)`` to test if ``obj`` implements
1197+
the :ref:`buffer protocol <bufferobjects>` at runtime. For use in type
1198+
annotations, either use :class:`~collections.abc.Buffer` or a union
1199+
that explicitly specifies the types your code supports (e.g.,
1200+
``bytes | bytearray | memoryview``).
1201+
1202+
:class:`!ByteString` was originally intended to be an abstract class that
1203+
would serve as a supertype of both :class:`bytes` and :class:`bytearray`.
1204+
However, since the ABC never had any methods, knowing that an object was an
1205+
instance of :class:`!ByteString` never actually told you anything useful
1206+
about the object. Other common buffer types such as :class:`memoryview` were
1207+
also never understood as subtypes of :class:`!ByteString` (either at
1208+
runtime or by static type checkers).
1209+
1210+
See :pep:`PEP 688 <688#current-options>` for more details.
11971211
(Contributed by Shantanu Jain in :gh:`91896`.)
11981212

11991213
* :mod:`datetime`: :class:`datetime.datetime`'s :meth:`~datetime.datetime.utcnow` and

Doc/whatsnew/3.15.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,25 @@ New modules
289289
Improved modules
290290
================
291291

292+
collections.abc
293+
---------------
294+
295+
* :class:`collections.abc.ByteString` has been removed from
296+
``collections.abc.__all__``. :class:`!collections.abc.ByteString` has been
297+
deprecated since Python 3.12, and is scheduled for removal in Python 3.17.
298+
299+
* The following statements now cause ``DeprecationWarning``\ s to be emitted at
300+
runtime:
301+
302+
* ``from collections.abc import ByteString``
303+
* ``import collections.abc; collections.abc.ByteString``.
304+
305+
``DeprecationWarning``\ s were already emitted if
306+
:class:`collections.abc.ByteString` was subclassed or used as the second
307+
argument to :func:`isinstance` or :func:`issubclass`, but warnings were not
308+
previously emitted if it was merely imported or accessed from the
309+
:mod:`!collections.abc` module.
310+
292311
dbm
293312
---
294313

@@ -671,6 +690,21 @@ typing
671690
as it was incorrectly infered in runtime before.
672691
(Contributed by Nikita Sobolev in :gh:`137191`.)
673692

693+
* :class:`typing.ByteString` has been removed from ``typing.__all__``.
694+
:class:`!typing.ByteString` has been deprecated since Python 3.9, and is
695+
scheduled for removal in Python 3.17.
696+
697+
* The following statements now cause ``DeprecationWarning``\ s to be emitted at
698+
runtime:
699+
700+
* ``from typing import ByteString``
701+
* ``import typing; typing.ByteString``.
702+
703+
``DeprecationWarning``\ s were already emitted if :class:`typing.ByteString`
704+
was subclassed or used as the second argument to :func:`isinstance` or
705+
:func:`issubclass`, but warnings were not previously emitted if it was merely
706+
imported or accessed from the :mod:`!typing` module.
707+
674708

675709
unicodedata
676710
-----------

Lib/_collections_abc.py

Lines changed: 17 additions & 3 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
@@ -1082,9 +1082,13 @@ def __instancecheck__(cls, instance):
10821082
return super().__instancecheck__(instance)
10831083

10841084
class ByteString(Sequence, metaclass=_DeprecateByteStringMeta):
1085-
"""This unifies bytes and bytearray.
1085+
"""Deprecated ABC serving as a common supertype of ``bytes`` and ``bytearray``.
10861086
1087-
XXX Should add all their methods.
1087+
This ABC is scheduled for removal in Python 3.17.
1088+
Use ``isinstance(obj, collections.abc.Buffer)`` to test if ``obj``
1089+
implements the buffer protocol at runtime. For use in type annotations,
1090+
either use ``Buffer`` or a union that explicitly specifies the types your
1091+
code supports (e.g., ``bytes | bytearray | memoryview``).
10881092
"""
10891093

10901094
__slots__ = ()
@@ -1161,3 +1165,13 @@ def __iadd__(self, values):
11611165

11621166
MutableSequence.register(list)
11631167
MutableSequence.register(bytearray)
1168+
1169+
_deprecated_ByteString = globals().pop("ByteString")
1170+
1171+
def __getattr__(attr):
1172+
if attr == "ByteString":
1173+
import warnings
1174+
warnings._deprecated("collections.abc.ByteString", remove=(3, 17))
1175+
globals()["ByteString"] = _deprecated_ByteString
1176+
return _deprecated_ByteString
1177+
raise AttributeError(f"module 'collections.abc' has no attribute {attr!r}")

0 commit comments

Comments
 (0)