Skip to content

Commit 7ea58ab

Browse files
committed
Merge remote-tracking branch 'upstream/main' into dicts
2 parents a4997f8 + 07b8d31 commit 7ea58ab

File tree

263 files changed

+6002
-2446
lines changed

Some content is hidden

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

263 files changed

+6002
-2446
lines changed

.github/workflows/mypy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@ jobs:
5959
cache: pip
6060
cache-dependency-path: Tools/requirements-dev.txt
6161
- run: pip install -r Tools/requirements-dev.txt
62+
- run: python3 Misc/mypy/make_symlinks.py --symlink
6263
- run: mypy --config-file ${{ matrix.target }}/mypy.ini

Doc/c-api/arg.rst

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,18 @@ There are three ways strings and buffers can be converted to C:
113113
``z`` (:class:`str` or ``None``) [const char \*]
114114
Like ``s``, but the Python object may also be ``None``, in which case the C
115115
pointer is set to ``NULL``.
116+
It is the same as ``s?`` with the C pointer was initialized to ``NULL``.
116117

117118
``z*`` (:class:`str`, :term:`bytes-like object` or ``None``) [Py_buffer]
118119
Like ``s*``, but the Python object may also be ``None``, in which case the
119120
``buf`` member of the :c:type:`Py_buffer` structure is set to ``NULL``.
121+
It is the same as ``s*?`` with the ``buf`` member of the :c:type:`Py_buffer`
122+
structure was initialized to ``NULL``.
120123

121124
``z#`` (:class:`str`, read-only :term:`bytes-like object` or ``None``) [const char \*, :c:type:`Py_ssize_t`]
122125
Like ``s#``, but the Python object may also be ``None``, in which case the C
123126
pointer is set to ``NULL``.
127+
It is the same as ``s#?`` with the C pointer was initialized to ``NULL``.
124128

125129
``y`` (read-only :term:`bytes-like object`) [const char \*]
126130
This format converts a bytes-like object to a C pointer to a
@@ -357,11 +361,37 @@ Other objects
357361

358362
.. versionadded:: 3.3
359363

360-
``(items)`` (:class:`tuple`) [*matching-items*]
361-
The object must be a Python sequence whose length is the number of format units
364+
``(items)`` (sequence) [*matching-items*]
365+
The object must be a Python sequence (except :class:`str`, :class:`bytes`
366+
or :class:`bytearray`) whose length is the number of format units
362367
in *items*. The C arguments must correspond to the individual format units in
363368
*items*. Format units for sequences may be nested.
364369

370+
If *items* contains format units which store a :ref:`borrowed buffer
371+
<c-arg-borrowed-buffer>` (``s``, ``s#``, ``z``, ``z#``, ``y``, or ``y#``)
372+
or a :term:`borrowed reference` (``S``, ``Y``, ``U``, ``O``, or ``O!``),
373+
the object must be a Python tuple.
374+
The *converter* for the ``O&`` format unit in *items* must not store
375+
a borrowed buffer or a borrowed reference.
376+
377+
.. versionchanged:: next
378+
:class:`str` and :class:`bytearray` objects no longer accepted as a sequence.
379+
380+
.. deprecated:: next
381+
Non-tuple sequences are deprecated if *items* contains format units
382+
which store a borrowed buffer or a borrowed reference.
383+
384+
``unit?`` (anything or ``None``) [*matching-variable(s)*]
385+
``?`` modifies the behavior of the preceding format unit.
386+
The C variable(s) corresponding to that parameter should be initialized
387+
to their default value --- when the argument is ``None``,
388+
:c:func:`PyArg_ParseTuple` does not touch the contents of the corresponding
389+
C variable(s).
390+
If the argument is not ``None``, it is parsed according to the specified
391+
format unit.
392+
393+
.. versionadded:: next
394+
365395
A few other characters have a meaning in a format string. These may not occur
366396
inside nested parentheses. They are:
367397

Doc/c-api/buffer.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ characteristic of being backed by a possibly large memory buffer. It is
2626
then desirable, in some situations, to access that buffer directly and
2727
without intermediate copying.
2828

29-
Python provides such a facility at the C level in the form of the :ref:`buffer
30-
protocol <bufferobjects>`. This protocol has two sides:
29+
Python provides such a facility at the C and Python level in the form of the
30+
:ref:`buffer protocol <bufferobjects>`. This protocol has two sides:
3131

3232
.. index:: single: PyBufferProcs (C type)
3333

3434
- on the producer side, a type can export a "buffer interface" which allows
3535
objects of that type to expose information about their underlying buffer.
36-
This interface is described in the section :ref:`buffer-structs`;
36+
This interface is described in the section :ref:`buffer-structs`; for
37+
Python see :ref:`python-buffer-protocol`.
3738

3839
- on the consumer side, several means are available to obtain a pointer to
39-
the raw underlying data of an object (for example a method parameter).
40+
the raw underlying data of an object (for example a method parameter). For
41+
Python see :class:`memoryview`.
4042

4143
Simple objects such as :class:`bytes` and :class:`bytearray` expose their
4244
underlying buffer in byte-oriented form. Other forms are possible; for example,
@@ -62,6 +64,10 @@ In both cases, :c:func:`PyBuffer_Release` must be called when the buffer
6264
isn't needed anymore. Failure to do so could lead to various issues such as
6365
resource leaks.
6466

67+
.. versionadded:: 3.12
68+
69+
The buffer protocol is now accessible in Python, see
70+
:ref:`python-buffer-protocol` and :class:`memoryview`.
6571

6672
.. _buffer-structure:
6773

Doc/c-api/monitoring.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,6 @@ would typically correspond to a python function.
205205
206206
.. versionadded:: 3.13
207207
208-
.. deprecated:: next
208+
.. deprecated:: 3.14
209209
210210
This function is :term:`soft deprecated`.

Doc/howto/curses.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ importing the :func:`curses.wrapper` function and using it like this::
145145
v = i-10
146146
stdscr.addstr(i, 0, '10 divided by {} is {}'.format(v, 10/v))
147147

148-
stdscr.refresh()
149-
stdscr.getkey()
148+
stdscr.refresh()
149+
stdscr.getkey()
150150

151151
wrapper(main)
152152

Doc/howto/free-threading-python.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,33 @@ to re-enable it in a thread-safe way in the 3.14 release. This overhead is
152152
expected to be reduced in upcoming Python release. We are aiming for an
153153
overhead of 10% or less on the pyperformance suite compared to the default
154154
GIL-enabled build.
155+
156+
157+
Behavioral changes
158+
==================
159+
160+
This section describes CPython behavioural changes with the free-threaded
161+
build.
162+
163+
164+
Context variables
165+
-----------------
166+
167+
In the free-threaded build, the flag :data:`~sys.flags.thread_inherit_context`
168+
is set to true by default which causes threads created with
169+
:class:`threading.Thread` to start with a copy of the
170+
:class:`~contextvars.Context()` of the caller of
171+
:meth:`~threading.Thread.start`. In the default GIL-enabled build, the flag
172+
defaults to false so threads start with an
173+
empty :class:`~contextvars.Context()`.
174+
175+
176+
Warning filters
177+
---------------
178+
179+
In the free-threaded build, the flag :data:`~sys.flags.context_aware_warnings`
180+
is set to true by default. In the default GIL-enabled build, the flag defaults
181+
to false. If the flag is true then the :class:`warnings.catch_warnings`
182+
context manager uses a context variable for warning filters. If the flag is
183+
false then :class:`~warnings.catch_warnings` modifies the global filters list,
184+
which is not thread-safe. See the :mod:`warnings` module for more details.

Doc/includes/typestruct.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ typedef struct _typeobject {
5454
iternextfunc tp_iternext;
5555

5656
/* Attribute descriptor and subclassing stuff */
57-
struct PyMethodDef *tp_methods;
58-
struct PyMemberDef *tp_members;
59-
struct PyGetSetDef *tp_getset;
57+
PyMethodDef *tp_methods;
58+
PyMemberDef *tp_members;
59+
PyGetSetDef *tp_getset;
6060
// Strong reference on a heap type, borrowed reference on a static type
61-
struct _typeobject *tp_base;
61+
PyTypeObject *tp_base;
6262
PyObject *tp_dict;
6363
descrgetfunc tp_descr_get;
6464
descrsetfunc tp_descr_set;
@@ -70,17 +70,26 @@ typedef struct _typeobject {
7070
inquiry tp_is_gc; /* For PyObject_IS_GC */
7171
PyObject *tp_bases;
7272
PyObject *tp_mro; /* method resolution order */
73-
PyObject *tp_cache;
74-
PyObject *tp_subclasses;
75-
PyObject *tp_weaklist;
73+
PyObject *tp_cache; /* no longer used */
74+
void *tp_subclasses; /* for static builtin types this is an index */
75+
PyObject *tp_weaklist; /* not used for static builtin types */
7676
destructor tp_del;
7777

78-
/* Type attribute cache version tag. Added in version 2.6 */
78+
/* Type attribute cache version tag. Added in version 2.6.
79+
* If zero, the cache is invalid and must be initialized.
80+
*/
7981
unsigned int tp_version_tag;
8082

8183
destructor tp_finalize;
8284
vectorcallfunc tp_vectorcall;
8385

8486
/* bitset of which type-watchers care about this type */
8587
unsigned char tp_watched;
88+
89+
/* Number of tp_version_tag values used.
90+
* Set to _Py_ATTR_CACHE_UNUSED if the attribute cache is
91+
* disabled for this type (e.g. due to custom MRO entries).
92+
* Otherwise, limited to MAX_VERSIONS_PER_CLASS (defined elsewhere).
93+
*/
94+
uint16_t tp_versions_used;
8695
} PyTypeObject;

Doc/library/annotationlib.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,12 @@ Functions
303303
.. function:: get_annotate_function(obj)
304304

305305
Retrieve the :term:`annotate function` for *obj*. Return :const:`!None`
306-
if *obj* does not have an annotate function.
306+
if *obj* does not have an annotate function. *obj* may be a class, function,
307+
module, or a namespace dictionary for a class. The last case is useful during
308+
class creation, e.g. in the ``__new__`` method of a metaclass.
307309

308310
This is usually equivalent to accessing the :attr:`~object.__annotate__`
309-
attribute of *obj*, but direct access to the attribute may return the wrong
310-
object in certain situations involving metaclasses. This function should be
311-
used instead of accessing the attribute directly.
311+
attribute of *obj*, but access through this public function is preferred.
312312

313313
.. versionadded:: 3.14
314314

Doc/library/concurrent.futures.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ the bytes over a shared :mod:`socket <socket>` or
298298

299299
The optional *initializer* and *initargs* arguments have the same
300300
meaning as for :class:`!ThreadPoolExecutor`: the initializer is run
301-
when each worker is created, though in this case it is run.in
301+
when each worker is created, though in this case it is run in
302302
the worker's interpreter. The executor serializes the *initializer*
303303
and *initargs* using :mod:`pickle` when sending them to the worker's
304304
interpreter.

Doc/library/contextlib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Functions and classes provided:
4949

5050
While many objects natively support use in with statements, sometimes a
5151
resource needs to be managed that isn't a context manager in its own right,
52-
and doesn't implement a ``close()`` method for use with ``contextlib.closing``
52+
and doesn't implement a ``close()`` method for use with ``contextlib.closing``.
5353

5454
An abstract example would be the following to ensure correct resource
5555
management::

0 commit comments

Comments
 (0)