Skip to content

Commit 7e4cf89

Browse files
committed
Merge branch 'ast-deprecation-warnings' of https://github.com/AlexWaygood/cpython into ast-deprecation-warnings
2 parents 8f86b9a + 6e9f5f5 commit 7e4cf89

File tree

80 files changed

+2443
-316
lines changed

Some content is hidden

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

80 files changed

+2443
-316
lines changed

Doc/howto/clinic.rst

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,19 +1033,36 @@ you're not permitted to use:
10331033
Using a return converter
10341034
------------------------
10351035

1036-
By default the impl function Argument Clinic generates for you returns ``PyObject *``.
1037-
But your C function often computes some C type, then converts it into the ``PyObject *``
1036+
By default, the impl function Argument Clinic generates for you returns
1037+
:c:type:`PyObject * <PyObject>`.
1038+
But your C function often computes some C type,
1039+
then converts it into the :c:type:`!PyObject *`
10381040
at the last moment. Argument Clinic handles converting your inputs from Python types
10391041
into native C types—why not have it convert your return value from a native C type
10401042
into a Python type too?
10411043

10421044
That's what a "return converter" does. It changes your impl function to return
10431045
some C type, then adds code to the generated (non-impl) function to handle converting
1044-
that value into the appropriate ``PyObject *``.
1046+
that value into the appropriate :c:type:`!PyObject *`.
10451047

10461048
The syntax for return converters is similar to that of parameter converters.
10471049
You specify the return converter like it was a return annotation on the
1048-
function itself. Return converters behave much the same as parameter converters;
1050+
function itself, using ``->`` notation.
1051+
1052+
For example:
1053+
1054+
.. code-block:: c
1055+
1056+
/*[clinic input]
1057+
add -> int
1058+
1059+
a: int
1060+
b: int
1061+
/
1062+
1063+
[clinic start generated code]*/
1064+
1065+
Return converters behave much the same as parameter converters;
10491066
they take arguments, the arguments are all keyword-only, and if you're not changing
10501067
any of the default arguments you can omit the parentheses.
10511068

@@ -1066,19 +1083,17 @@ Currently Argument Clinic supports only a few return converters:
10661083
.. code-block:: none
10671084
10681085
bool
1086+
double
1087+
float
10691088
int
1070-
unsigned int
10711089
long
1072-
unsigned int
1073-
size_t
10741090
Py_ssize_t
1075-
float
1076-
double
1077-
DecodeFSDefault
1091+
size_t
1092+
unsigned int
1093+
unsigned long
10781094
1079-
None of these take parameters. For the first three, return -1 to indicate
1080-
error. For ``DecodeFSDefault``, the return type is ``const char *``; return a ``NULL``
1081-
pointer to indicate an error.
1095+
None of these take parameters.
1096+
For all of these, return ``-1`` to indicate error.
10821097

10831098
To see all the return converters Argument Clinic supports, along with
10841099
their parameters (if any),

Doc/library/collections.abc.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ ABC Inherits from Abstract Methods Mi
177177
:class:`AsyncIterable` [1]_ ``__aiter__``
178178
:class:`AsyncIterator` [1]_ :class:`AsyncIterable` ``__anext__`` ``__aiter__``
179179
:class:`AsyncGenerator` [1]_ :class:`AsyncIterator` ``asend``, ``athrow`` ``aclose``, ``__aiter__``, ``__anext__``
180+
:class:`Buffer` [1]_ ``__buffer__``
180181
============================== ====================== ======================= ====================================================
181182

182183

@@ -272,6 +273,12 @@ Collections Abstract Base Classes -- Detailed Descriptions
272273
The index() method added support for *stop* and *start*
273274
arguments.
274275

276+
.. deprecated-removed:: 3.12 3.14
277+
The :class:`ByteString` ABC has been deprecated.
278+
For use in typing, prefer a union, like ``bytes | bytearray``, or
279+
:class:`collections.abc.Buffer`.
280+
For use as an ABC, prefer :class:`Sequence` or :class:`collections.abc.Buffer`.
281+
275282
.. class:: Set
276283
MutableSet
277284

@@ -346,6 +353,13 @@ Collections Abstract Base Classes -- Detailed Descriptions
346353

347354
.. versionadded:: 3.6
348355

356+
.. class:: Buffer
357+
358+
ABC for classes that provide the :meth:`~object.__buffer__` method,
359+
implementing the :ref:`buffer protocol <bufferobjects>`. See :pep:`688`.
360+
361+
.. versionadded:: 3.12
362+
349363
Examples and Recipes
350364
--------------------
351365

Doc/library/functools.rst

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,10 @@ The :mod:`functools` module defines the following functions:
110110
``__slots__`` without including ``__dict__`` as one of the defined slots
111111
(as such classes don't provide a ``__dict__`` attribute at all).
112112

113-
If a mutable mapping is not available or if space-efficient key sharing
114-
is desired, an effect similar to :func:`cached_property` can be achieved
115-
by a stacking :func:`property` on top of :func:`cache`::
116-
117-
class DataSet:
118-
def __init__(self, sequence_of_numbers):
119-
self._data = sequence_of_numbers
120-
121-
@property
122-
@cache
123-
def stdev(self):
124-
return statistics.stdev(self._data)
113+
If a mutable mapping is not available or if space-efficient key sharing is
114+
desired, an effect similar to :func:`cached_property` can also be achieved by
115+
stacking :func:`property` on top of :func:`lru_cache`. See
116+
:ref:`faq-cache-method-calls` for more details on how this differs from :func:`cached_property`.
125117

126118
.. versionadded:: 3.8
127119

Doc/library/inspect.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,39 @@ the following flags:
16031603
for any introspection needs.
16041604

16051605

1606+
Buffer flags
1607+
------------
1608+
1609+
.. class:: BufferFlags
1610+
1611+
This is an :class:`enum.IntFlag` that represents the flags that
1612+
can be passed to the :meth:`~object.__buffer__` method of objects
1613+
implementing the :ref:`buffer protocol <bufferobjects>`.
1614+
1615+
The meaning of the flags is explained at :ref:`buffer-request-types`.
1616+
1617+
.. attribute:: BufferFlags.SIMPLE
1618+
.. attribute:: BufferFlags.WRITABLE
1619+
.. attribute:: BufferFlags.FORMAT
1620+
.. attribute:: BufferFlags.ND
1621+
.. attribute:: BufferFlags.STRIDES
1622+
.. attribute:: BufferFlags.C_CONTIGUOUS
1623+
.. attribute:: BufferFlags.F_CONTIGUOUS
1624+
.. attribute:: BufferFlags.ANY_CONTIGUOUS
1625+
.. attribute:: BufferFlags.INDIRECT
1626+
.. attribute:: BufferFlags.CONTIG
1627+
.. attribute:: BufferFlags.CONTIG_RO
1628+
.. attribute:: BufferFlags.STRIDED
1629+
.. attribute:: BufferFlags.STRIDED_RO
1630+
.. attribute:: BufferFlags.RECORDS
1631+
.. attribute:: BufferFlags.RECORDS_RO
1632+
.. attribute:: BufferFlags.FULL
1633+
.. attribute:: BufferFlags.FULL_RO
1634+
.. attribute:: BufferFlags.READ
1635+
.. attribute:: BufferFlags.WRITE
1636+
1637+
.. versionadded:: 3.12
1638+
16061639
.. _inspect-module-cli:
16071640

16081641
Command Line Interface

Doc/library/pathlib.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ call fails (for example because the path doesn't exist).
855855
.. versionadded:: 3.5
856856

857857

858-
.. method:: Path.glob(pattern)
858+
.. method:: Path.glob(pattern, *, case_sensitive=None)
859859

860860
Glob the given relative *pattern* in the directory represented by this path,
861861
yielding all matching files (of any kind)::
@@ -876,6 +876,11 @@ call fails (for example because the path doesn't exist).
876876
PosixPath('setup.py'),
877877
PosixPath('test_pathlib.py')]
878878

879+
By default, or when the *case_sensitive* keyword-only argument is set to
880+
``None``, this method matches paths using platform-specific casing rules:
881+
typically, case-sensitive on POSIX, and case-insensitive on Windows.
882+
Set *case_sensitive* to ``True`` or ``False`` to override this behaviour.
883+
879884
.. note::
880885
Using the "``**``" pattern in large directory trees may consume
881886
an inordinate amount of time.
@@ -886,6 +891,9 @@ call fails (for example because the path doesn't exist).
886891
Return only directories if *pattern* ends with a pathname components
887892
separator (:data:`~os.sep` or :data:`~os.altsep`).
888893

894+
.. versionadded:: 3.12
895+
The *case_sensitive* argument.
896+
889897
.. method:: Path.group()
890898

891899
Return the name of the group owning the file. :exc:`KeyError` is raised
@@ -1271,7 +1279,7 @@ call fails (for example because the path doesn't exist).
12711279
.. versionadded:: 3.6
12721280
The *strict* argument (pre-3.6 behavior is strict).
12731281

1274-
.. method:: Path.rglob(pattern)
1282+
.. method:: Path.rglob(pattern, *, case_sensitive=None)
12751283

12761284
Glob the given relative *pattern* recursively. This is like calling
12771285
:func:`Path.glob` with "``**/``" added in front of the *pattern*, where
@@ -1284,12 +1292,20 @@ call fails (for example because the path doesn't exist).
12841292
PosixPath('setup.py'),
12851293
PosixPath('test_pathlib.py')]
12861294

1295+
By default, or when the *case_sensitive* keyword-only argument is set to
1296+
``None``, this method matches paths using platform-specific casing rules:
1297+
typically, case-sensitive on POSIX, and case-insensitive on Windows.
1298+
Set *case_sensitive* to ``True`` or ``False`` to override this behaviour.
1299+
12871300
.. audit-event:: pathlib.Path.rglob self,pattern pathlib.Path.rglob
12881301

12891302
.. versionchanged:: 3.11
12901303
Return only directories if *pattern* ends with a pathname components
12911304
separator (:data:`~os.sep` or :data:`~os.altsep`).
12921305

1306+
.. versionadded:: 3.12
1307+
The *case_sensitive* argument.
1308+
12931309
.. method:: Path.rmdir()
12941310

12951311
Remove this directory. The directory must be empty.

Doc/library/socket.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,17 @@ Constants
509509
.. versionadded:: 3.9
510510

511511

512+
.. data:: AF_DIVERT
513+
PF_DIVERT
514+
515+
These two constants, documented in the FreeBSD divert(4) manual page, are
516+
also defined in the socket module.
517+
518+
.. availability:: FreeBSD >= 14.0.
519+
520+
.. versionadded:: 3.12
521+
522+
512523
.. data:: AF_PACKET
513524
PF_PACKET
514525
PACKET_*

Doc/library/typing.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,8 +2139,7 @@ Corresponding to collections in :mod:`collections.abc`
21392139
annotate arguments of any of the types mentioned above.
21402140

21412141
.. deprecated:: 3.9
2142-
:class:`collections.abc.ByteString` now supports subscripting (``[]``).
2143-
See :pep:`585` and :ref:`types-genericalias`.
2142+
Prefer :class:`collections.abc.Buffer`, or a union like ``bytes | bytearray | memoryview``.
21442143

21452144
.. class:: Collection(Sized, Iterable[T_co], Container[T_co])
21462145

Doc/reference/datamodel.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2865,6 +2865,47 @@ a :exc:`TypeError`.
28652865
The specification for the Python ``match`` statement.
28662866

28672867

2868+
.. _python-buffer-protocol:
2869+
2870+
Emulating buffer types
2871+
----------------------
2872+
2873+
The :ref:`buffer protocol <bufferobjects>` provides a way for Python
2874+
objects to expose efficient access to a low-level memory array. This protocol
2875+
is implemented by builtin types such as :class:`bytes` and :class:`memoryview`,
2876+
and third-party libraries may define additional buffer types.
2877+
2878+
While buffer types are usually implemented in C, it is also possible to
2879+
implement the protocol in Python.
2880+
2881+
.. method:: object.__buffer__(self, flags)
2882+
2883+
Called when a buffer is requested from *self* (for example, by the
2884+
:class:`memoryview` constructor). The *flags* argument is an integer
2885+
representing the kind of buffer requested, affecting for example whether
2886+
the returned buffer is read-only or writable. :class:`inspect.BufferFlags`
2887+
provides a convenient way to interpret the flags. The method must return
2888+
a :class:`memoryview` object.
2889+
2890+
.. method:: object.__release_buffer__(self, buffer)
2891+
2892+
Called when a buffer is no longer needed. The *buffer* argument is a
2893+
:class:`memoryview` object that was previously returned by
2894+
:meth:`~object.__buffer__`. The method must release any resources associated
2895+
with the buffer. This method should return ``None``.
2896+
Buffer objects that do not need to perform any cleanup are not required
2897+
to implement this method.
2898+
2899+
.. versionadded:: 3.12
2900+
2901+
.. seealso::
2902+
2903+
:pep:`688` - Making the buffer protocol accessible in Python
2904+
Introduces the Python ``__buffer__`` and ``__release_buffer__`` methods.
2905+
2906+
:class:`collections.abc.Buffer`
2907+
ABC for buffer types.
2908+
28682909
.. _special-lookup:
28692910

28702911
Special method lookup

Doc/whatsnew/3.12.rst

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,17 @@ Summary -- Release highlights
6868
6969
New typing features:
7070

71+
* :pep:`688`: Making the buffer protocol accessible in Python
72+
7173
* :ref:`whatsnew312-pep692`
7274

75+
* :pep:`698`: Override Decorator for Static Typing
76+
7377
Important deprecations, removals or restrictions:
7478

75-
* :pep:`623`, Remove wstr from Unicode
79+
* :pep:`623`: Remove wstr from Unicode
7680

77-
* :pep:`632`, Remove the ``distutils`` package.
81+
* :pep:`632`: Remove the ``distutils`` package
7882

7983
Improved Error Messages
8084
=======================
@@ -149,6 +153,19 @@ New Features
149153
In Python 3.14, the default will switch to ``'data'``.
150154
(Contributed by Petr Viktorin in :pep:`706`.)
151155

156+
PEP 688: Making the buffer protocol accessible in Python
157+
--------------------------------------------------------
158+
159+
:pep:`688` introduces a way to use the :ref:`buffer protocol <bufferobjects>`
160+
from Python code. Classes that implement the :meth:`~object.__buffer__` method
161+
are now usable as buffer types.
162+
163+
The new :class:`collections.abc.Buffer` ABC provides a standard
164+
way to represent buffer objects, for example in type annotations.
165+
The new :class:`inspect.BufferFlags` enum represents the flags that
166+
can be used to customize buffer creation.
167+
(Contributed by Jelle Zijlstra in :gh:`102500`.)
168+
152169
New Features Related to Type Hints
153170
==================================
154171

@@ -179,7 +196,6 @@ See :pep:`692` for more details.
179196

180197
(PEP written by Franek Magiera)
181198

182-
183199
Other Language Changes
184200
======================
185201

@@ -780,6 +796,11 @@ Pending Removal in Python 3.14
780796

781797
(Contributed by Jason R. Coombs and Hugo van Kemenade in :gh:`93963`.)
782798

799+
* Deprecated :class:`collections.abc.ByteString`.
800+
Prefer :class:`Sequence` or :class:`collections.abc.Buffer`.
801+
For use in typing, prefer a union, like ``bytes | bytearray``, or :class:`collections.abc.Buffer`.
802+
(Contributed by Shantanu Jain in :gh:`91896`.)
803+
783804
* Creating immutable types (:data:`Py_TPFLAGS_IMMUTABLETYPE`) with mutable
784805
bases using the C API.
785806

@@ -837,7 +858,7 @@ although there is currently no date scheduled for their removal.
837858

838859
* The following :mod:`ast` features have been deprecated in documentation since
839860
Python 3.8, now cause a :exc:`DeprecationWarning` to be emitted at runtime
840-
when they are accessed or used, and may be removed in a future version of Python:
861+
when they are accessed or used, and will be removed in Python 3.14.
841862

842863
* :class:`!ast.Num`
843864
* :class:`!ast.Str`

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)