Skip to content

Commit 576c914

Browse files
Merge remote-tracking branch 'origin/main' into more_load_attr
2 parents fe02743 + 2eea959 commit 576c914

File tree

164 files changed

+2340
-1592
lines changed

Some content is hidden

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

164 files changed

+2340
-1592
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ jobs:
235235
strategy:
236236
fail-fast: false
237237
matrix:
238-
openssl_ver: [1.1.1s, 3.0.7]
238+
openssl_ver: [1.1.1s, 3.0.7, 3.1.0-beta1]
239239
env:
240240
OPENSSL_VER: ${{ matrix.openssl_ver }}
241241
MULTISSL_DIR: ${{ github.workspace }}/multissl

.github/workflows/doc.yml

-10
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,8 @@ jobs:
5050
run: make -C Doc/ venv
5151
- name: 'Check documentation'
5252
run: make -C Doc/ check
53-
- name: 'Upload NEWS'
54-
uses: actions/upload-artifact@v3
55-
with:
56-
name: NEWS
57-
path: Doc/build/NEWS
5853
- name: 'Build HTML documentation'
5954
run: make -C Doc/ SPHINXOPTS="-q" SPHINXERRORHANDLING="-W --keep-going" html
60-
- name: 'Upload docs'
61-
uses: actions/upload-artifact@v3
62-
with:
63-
name: doc-html
64-
path: Doc/build/html
6555

6656
# Run "doctest" on HEAD as new syntax doesn't exist in the latest stable release
6757
doctest:

Doc/c-api/apiabiversion.rst

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ See :ref:`stable` for a discussion of API and ABI stability across versions.
5858
Thus ``3.4.1a2`` is hexversion ``0x030401a2`` and ``3.10.0`` is
5959
hexversion ``0x030a00f0``.
6060

61+
Use this for numeric comparisons, e.g. ``#if PY_VERSION_HEX >= ...``.
62+
6163
This version is also available via the symbol :data:`Py_Version`.
6264

6365
.. c:var:: const unsigned long Py_Version

Doc/c-api/arg.rst

+35-19
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,39 @@ These formats allow accessing an object as a contiguous chunk of memory.
3434
You don't have to provide raw storage for the returned unicode or bytes
3535
area.
3636

37-
In general, when a format sets a pointer to a buffer, the buffer is
38-
managed by the corresponding Python object, and the buffer shares
39-
the lifetime of this object. You won't have to release any memory yourself.
40-
The only exceptions are ``es``, ``es#``, ``et`` and ``et#``.
41-
42-
However, when a :c:type:`Py_buffer` structure gets filled, the underlying
43-
buffer is locked so that the caller can subsequently use the buffer even
44-
inside a :c:type:`Py_BEGIN_ALLOW_THREADS` block without the risk of mutable data
45-
being resized or destroyed. As a result, **you have to call**
46-
:c:func:`PyBuffer_Release` after you have finished processing the data (or
47-
in any early abort case).
48-
4937
Unless otherwise stated, buffers are not NUL-terminated.
5038

51-
Some formats require a read-only :term:`bytes-like object`, and set a
52-
pointer instead of a buffer structure. They work by checking that
53-
the object's :c:member:`PyBufferProcs.bf_releasebuffer` field is ``NULL``,
54-
which disallows mutable objects such as :class:`bytearray`.
39+
There are three ways strings and buffers can be converted to C:
40+
41+
* Formats such as ``y*`` and ``s*`` fill a :c:type:`Py_buffer` structure.
42+
This locks the underlying buffer so that the caller can subsequently use
43+
the buffer even inside a :c:type:`Py_BEGIN_ALLOW_THREADS`
44+
block without the risk of mutable data being resized or destroyed.
45+
As a result, **you have to call** :c:func:`PyBuffer_Release` after you have
46+
finished processing the data (or in any early abort case).
47+
48+
* The ``es``, ``es#``, ``et`` and ``et#`` formats allocate the result buffer.
49+
**You have to call** :c:func:`PyMem_Free` after you have finished
50+
processing the data (or in any early abort case).
51+
52+
* .. _c-arg-borrowed-buffer:
53+
54+
Other formats take a :class:`str` or a read-only :term:`bytes-like object`,
55+
such as :class:`bytes`, and provide a ``const char *`` pointer to
56+
its buffer.
57+
In this case the buffer is "borrowed": it is managed by the corresponding
58+
Python object, and shares the lifetime of this object.
59+
You won't have to release any memory yourself.
60+
61+
To ensure that the underlying buffer may be safely borrowed, the object's
62+
:c:member:`PyBufferProcs.bf_releasebuffer` field must be ``NULL``.
63+
This disallows common mutable objects such as :class:`bytearray`,
64+
but also some read-only objects such as :class:`memoryview` of
65+
:class:`bytes`.
66+
67+
Besides this ``bf_releasebuffer`` requirement, there is no check to verify
68+
whether the input object is immutable (e.g. whether it would honor a request
69+
for a writable buffer, or whether another thread can mutate the data).
5570

5671
.. note::
5772

@@ -89,7 +104,7 @@ which disallows mutable objects such as :class:`bytearray`.
89104
Unicode objects are converted to C strings using ``'utf-8'`` encoding.
90105

91106
``s#`` (:class:`str`, read-only :term:`bytes-like object`) [const char \*, :c:type:`Py_ssize_t`]
92-
Like ``s*``, except that it doesn't accept mutable objects.
107+
Like ``s*``, except that it provides a :ref:`borrowed buffer <c-arg-borrowed-buffer>`.
93108
The result is stored into two C variables,
94109
the first one a pointer to a C string, the second one its length.
95110
The string may contain embedded null bytes. Unicode objects are converted
@@ -108,8 +123,9 @@ which disallows mutable objects such as :class:`bytearray`.
108123
pointer is set to ``NULL``.
109124

110125
``y`` (read-only :term:`bytes-like object`) [const char \*]
111-
This format converts a bytes-like object to a C pointer to a character
112-
string; it does not accept Unicode objects. The bytes buffer must not
126+
This format converts a bytes-like object to a C pointer to a
127+
:ref:`borrowed <c-arg-borrowed-buffer>` character string;
128+
it does not accept Unicode objects. The bytes buffer must not
113129
contain embedded null bytes; if it does, a :exc:`ValueError`
114130
exception is raised.
115131

Doc/c-api/structures.rst

+18-17
Original file line numberDiff line numberDiff line change
@@ -228,29 +228,30 @@ Implementing functions and methods
228228
Structure used to describe a method of an extension type. This structure has
229229
four fields:
230230
231-
+------------------+---------------+-------------------------------+
232-
| Field | C Type | Meaning |
233-
+==================+===============+===============================+
234-
| :attr:`ml_name` | const char \* | name of the method |
235-
+------------------+---------------+-------------------------------+
236-
| :attr:`ml_meth` | PyCFunction | pointer to the C |
237-
| | | implementation |
238-
+------------------+---------------+-------------------------------+
239-
| :attr:`ml_flags` | int | flag bits indicating how the |
240-
| | | call should be constructed |
241-
+------------------+---------------+-------------------------------+
242-
| :attr:`ml_doc` | const char \* | points to the contents of the |
243-
| | | docstring |
244-
+------------------+---------------+-------------------------------+
245-
246-
The :attr:`ml_meth` is a C function pointer. The functions may be of different
231+
.. c:member:: const char* ml_name
232+
233+
name of the method
234+
235+
.. c:member:: PyCFunction ml_meth
236+
237+
pointer to the C implementation
238+
239+
.. c:member:: int ml_flags
240+
241+
flags bits indicating how the call should be constructed
242+
243+
.. c:member:: const char* ml_doc
244+
245+
points to the contents of the docstring
246+
247+
The :c:member:`ml_meth` is a C function pointer. The functions may be of different
247248
types, but they always return :c:expr:`PyObject*`. If the function is not of
248249
the :c:type:`PyCFunction`, the compiler will require a cast in the method table.
249250
Even though :c:type:`PyCFunction` defines the first parameter as
250251
:c:expr:`PyObject*`, it is common that the method implementation uses the
251252
specific C type of the *self* object.
252253
253-
The :attr:`ml_flags` field is a bitfield which can include the following flags.
254+
The :c:member:`ml_flags` field is a bitfield which can include the following flags.
254255
The individual flags indicate either a calling convention or a binding
255256
convention.
256257

Doc/c-api/typeobj.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Quick Reference
147147
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
148148
| :c:member:`~PyTypeObject.tp_vectorcall` | :c:type:`vectorcallfunc` | | | | | |
149149
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
150-
| :c:member:`~PyTypeObject.tp_watched` | char | | | | | |
150+
| [:c:member:`~PyTypeObject.tp_watched`] | char | | | | | |
151151
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
152152

153153
.. [#slots]

Doc/faq/programming.rst

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ Yes. The coding style required for standard library modules is documented as
113113
Core Language
114114
=============
115115

116+
.. _faq-unboundlocalerror:
117+
116118
Why am I getting an UnboundLocalError when the variable has a value?
117119
--------------------------------------------------------------------
118120

Doc/library/asyncio-eventloop.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,8 @@ Watching file descriptors
932932

933933
.. method:: loop.remove_reader(fd)
934934

935-
Stop monitoring the *fd* file descriptor for read availability.
935+
Stop monitoring the *fd* file descriptor for read availability. Returns
936+
``True`` if *fd* was previously being monitored for reads.
936937

937938
.. method:: loop.add_writer(fd, callback, *args)
938939

@@ -945,7 +946,8 @@ Watching file descriptors
945946

946947
.. method:: loop.remove_writer(fd)
947948

948-
Stop monitoring the *fd* file descriptor for write availability.
949+
Stop monitoring the *fd* file descriptor for write availability. Returns
950+
``True`` if *fd* was previously being monitored for writes.
949951

950952
See also :ref:`Platform Support <asyncio-platform-support>` section
951953
for some limitations of these methods.

Doc/library/contextvars.rst

+5
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ Manual Context Management
144144
To get a copy of the current context use the
145145
:func:`~contextvars.copy_context` function.
146146

147+
Every thread will have a different top-level :class:`~contextvars.Context`
148+
object. This means that a :class:`ContextVar` object behaves in a similar
149+
fashion to :func:`threading.local()` when values are assigned in different
150+
threads.
151+
147152
Context implements the :class:`collections.abc.Mapping` interface.
148153

149154
.. method:: run(callable, *args, **kwargs)

Doc/library/functions.rst

+4
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,10 @@ are always available. They are listed here in alphabetical order.
17331733
.. versionchanged:: 3.8
17341734
The *start* parameter can be specified as a keyword argument.
17351735

1736+
.. versionchanged:: 3.12 Summation of floats switched to an algorithm
1737+
that gives higher accuracy on most builds.
1738+
1739+
17361740
.. class:: super()
17371741
super(type, object_or_type=None)
17381742

Doc/library/imaplib.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ IMAP4 Objects
187187
-------------
188188

189189
All IMAP4rev1 commands are represented by methods of the same name, either
190-
upper-case or lower-case.
190+
uppercase or lowercase.
191191

192192
All arguments to commands are converted to strings, except for ``AUTHENTICATE``,
193193
and the last argument to ``APPEND`` which is passed as an IMAP4 literal. If

Doc/library/inspect.rst

+23-2
Original file line numberDiff line numberDiff line change
@@ -343,15 +343,36 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
343343

344344
.. function:: iscoroutinefunction(object)
345345

346-
Return ``True`` if the object is a :term:`coroutine function`
347-
(a function defined with an :keyword:`async def` syntax).
346+
Return ``True`` if the object is a :term:`coroutine function` (a function
347+
defined with an :keyword:`async def` syntax), a :func:`functools.partial`
348+
wrapping a :term:`coroutine function`, or a sync function marked with
349+
:func:`markcoroutinefunction`.
348350

349351
.. versionadded:: 3.5
350352

351353
.. versionchanged:: 3.8
352354
Functions wrapped in :func:`functools.partial` now return ``True`` if the
353355
wrapped function is a :term:`coroutine function`.
354356

357+
.. versionchanged:: 3.12
358+
Sync functions marked with :func:`markcoroutinefunction` now return
359+
``True``.
360+
361+
362+
.. function:: markcoroutinefunction(func)
363+
364+
Decorator to mark a callable as a :term:`coroutine function` if it would not
365+
otherwise be detected by :func:`iscoroutinefunction`.
366+
367+
This may be of use for sync functions that return a :term:`coroutine`, if
368+
the function is passed to an API that requires :func:`iscoroutinefunction`.
369+
370+
When possible, using an :keyword:`async def` function is preferred. Also
371+
acceptable is calling the function and testing the return with
372+
:func:`iscoroutine`.
373+
374+
.. versionadded:: 3.12
375+
355376

356377
.. function:: iscoroutine(object)
357378

Doc/library/itertools.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,8 @@ which incur interpreter overhead.
834834
return chain.from_iterable(repeat(tuple(iterable), n))
835835

836836
def dotproduct(vec1, vec2):
837-
return sum(map(operator.mul, vec1, vec2))
837+
"Compute a sum of products."
838+
return sum(starmap(operator.mul, zip(vec1, vec2, strict=True)))
838839

839840
def convolve(signal, kernel):
840841
# See: https://betterexplained.com/articles/intuitive-convolution/
@@ -846,7 +847,7 @@ which incur interpreter overhead.
846847
window = collections.deque([0], maxlen=n) * n
847848
for x in chain(signal, repeat(0, n-1)):
848849
window.append(x)
849-
yield sum(map(operator.mul, kernel, window))
850+
yield dotproduct(kernel, window)
850851

851852
def polynomial_from_roots(roots):
852853
"""Compute a polynomial's coefficients from its roots.

Doc/library/math.rst

+1-6
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,7 @@ Number-theoretic and representation functions
108108
.. function:: fsum(iterable)
109109

110110
Return an accurate floating point sum of values in the iterable. Avoids
111-
loss of precision by tracking multiple intermediate partial sums:
112-
113-
>>> sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
114-
0.9999999999999999
115-
>>> fsum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
116-
1.0
111+
loss of precision by tracking multiple intermediate partial sums.
117112

118113
The algorithm's accuracy depends on IEEE-754 arithmetic guarantees and the
119114
typical case where the rounding mode is half-even. On some non-Windows

Doc/library/pathlib.rst

+11-3
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ Pure paths provide the following methods and properties:
490490
True
491491

492492

493-
.. method:: PurePath.is_relative_to(*other)
493+
.. method:: PurePath.is_relative_to(other)
494494

495495
Return whether or not this path is relative to the *other* path.
496496

@@ -502,6 +502,10 @@ Pure paths provide the following methods and properties:
502502

503503
.. versionadded:: 3.9
504504

505+
.. deprecated-removed:: 3.12 3.14
506+
507+
Passing additional arguments is deprecated; if supplied, they are joined
508+
with *other*.
505509

506510
.. method:: PurePath.is_reserved()
507511

@@ -564,7 +568,7 @@ Pure paths provide the following methods and properties:
564568
True
565569

566570

567-
.. method:: PurePath.relative_to(*other, walk_up=False)
571+
.. method:: PurePath.relative_to(other, walk_up=False)
568572

569573
Compute a version of this path relative to the path represented by
570574
*other*. If it's impossible, :exc:`ValueError` is raised::
@@ -581,7 +585,7 @@ Pure paths provide the following methods and properties:
581585
raise ValueError(error_message.format(str(self), str(formatted)))
582586
ValueError: '/etc/passwd' is not in the subpath of '/usr' OR one path is relative and the other is absolute.
583587

584-
When *walk_up* is False (the default), the path must start with *other*.
588+
When *walk_up* is False (the default), the path must start with *other*.
585589
When the argument is True, ``..`` entries may be added to form the
586590
relative path. In all other cases, such as the paths referencing
587591
different drives, :exc:`ValueError` is raised.::
@@ -605,6 +609,10 @@ When *walk_up* is False (the default), the path must start with *other*.
605609
.. versionadded:: 3.12
606610
The *walk_up* argument (old behavior is the same as ``walk_up=False``).
607611

612+
.. deprecated-removed:: 3.12 3.14
613+
614+
Passing additional positional arguments is deprecated; if supplied,
615+
they are joined with *other*.
608616

609617
.. method:: PurePath.with_name(name)
610618

Doc/library/re.rst

+3-4
Original file line numberDiff line numberDiff line change
@@ -591,10 +591,9 @@ character ``'$'``.
591591

592592
``\w``
593593
For Unicode (str) patterns:
594-
Matches Unicode word characters; this includes most characters
595-
that can be part of a word in any language, as well as numbers and
596-
the underscore. If the :const:`ASCII` flag is used, only
597-
``[a-zA-Z0-9_]`` is matched.
594+
Matches Unicode word characters; this includes alphanumeric characters (as defined by :meth:`str.isalnum`)
595+
as well as the underscore (``_``).
596+
If the :const:`ASCII` flag is used, only ``[a-zA-Z0-9_]`` is matched.
598597

599598
For 8-bit (bytes) patterns:
600599
Matches characters considered alphanumeric in the ASCII character set;

Doc/library/sched.rst

+11-5
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,22 @@ Example::
4444
... print(time.time())
4545
... s.enter(10, 1, print_time)
4646
... s.enter(5, 2, print_time, argument=('positional',))
47+
... # despite having higher priority, 'keyword' runs after 'positional' as enter() is relative
4748
... s.enter(5, 1, print_time, kwargs={'a': 'keyword'})
49+
... s.enterabs(1_650_000_000, 10, print_time, argument=("first enterabs",))
50+
... s.enterabs(1_650_000_000, 5, print_time, argument=("second enterabs",))
4851
... s.run()
4952
... print(time.time())
5053
...
5154
>>> print_some_times()
52-
930343690.257
53-
From print_time 930343695.274 positional
54-
From print_time 930343695.275 keyword
55-
From print_time 930343700.273 default
56-
930343700.276
55+
1652342830.3640375
56+
From print_time 1652342830.3642538 second enterabs
57+
From print_time 1652342830.3643398 first enterabs
58+
From print_time 1652342835.3694863 positional
59+
From print_time 1652342835.3696074 keyword
60+
From print_time 1652342840.369612 default
61+
1652342840.3697174
62+
5763

5864
.. _scheduler-objects:
5965

0 commit comments

Comments
 (0)