Skip to content

Commit 0237f8e

Browse files
committed
Merge branch 'main' into gh-148874/with-signal-exit-skip
2 parents 658c05f + 40dc61a commit 0237f8e

97 files changed

Lines changed: 3917 additions & 2169 deletions

File tree

Some content is hidden

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

.github/workflows/documentation-links.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

.github/workflows/reusable-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
with:
5757
python-version: '3'
5858
cache: 'pip'
59-
cache-dependency-path: 'Doc/requirements.txt'
59+
cache-dependency-path: 'Doc/pylock.toml'
6060
- name: 'Install build dependencies'
6161
run: make -C Doc/ venv
6262

Doc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ JOBS = auto
1313
PAPER =
1414
SOURCES =
1515
DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py)
16-
REQUIREMENTS = requirements.txt
16+
REQUIREMENTS = pylock.toml
1717
SPHINXERRORHANDLING = --fail-on-warning
1818

1919
# Internal variables.

Doc/c-api/concrete.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ Other Objects
112112
picklebuffer.rst
113113
weakref.rst
114114
capsule.rst
115+
sentinel.rst
115116
frame.rst
116117
gen.rst
117118
coro.rst

Doc/c-api/sentinel.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.. highlight:: c
2+
3+
.. _sentinelobjects:
4+
5+
Sentinel objects
6+
----------------
7+
8+
.. c:var:: PyTypeObject PySentinel_Type
9+
10+
This instance of :c:type:`PyTypeObject` represents the Python
11+
:class:`sentinel` type. This is the same object as :class:`sentinel`.
12+
13+
.. versionadded:: next
14+
15+
.. c:function:: int PySentinel_Check(PyObject *o)
16+
17+
Return true if *o* is a :class:`sentinel` object. The :class:`sentinel` type
18+
does not allow subclasses, so this check is exact.
19+
20+
.. versionadded:: next
21+
22+
.. c:function:: PyObject* PySentinel_New(const char *name, const char *module_name)
23+
24+
Return a new :class:`sentinel` object with :attr:`~sentinel.__name__` set to
25+
*name* and :attr:`~sentinel.__module__` set to *module_name*.
26+
*name* must not be ``NULL``. If *module_name* is ``NULL``, :attr:`~sentinel.__module__`
27+
is set to ``None``.
28+
Return ``NULL`` with an exception set on failure.
29+
30+
For pickling to work, *module_name* must be the name of an importable
31+
module, and the sentinel must be accessible from that module under a
32+
path matching *name*. Pickle treats *name* as a global variable name
33+
in *module_name* (see :meth:`object.__reduce__`).
34+
35+
.. versionadded:: next

Doc/data/refcounts.dat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,6 +2037,10 @@ PySeqIter_Check:PyObject *:op:0:
20372037
PySeqIter_New:PyObject*::+1:
20382038
PySeqIter_New:PyObject*:seq:0:
20392039

2040+
PySentinel_New:PyObject*::+1:
2041+
PySentinel_New:const char*:name::
2042+
PySentinel_New:const char*:module_name::
2043+
20402044
PySequence_Check:int:::
20412045
PySequence_Check:PyObject*:o:0:
20422046

Doc/library/ast.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ The abstract grammar is currently defined as follows:
3535
:language: asdl
3636

3737

38+
.. _ast_nodes:
39+
3840
Node classes
3941
------------
4042

@@ -164,8 +166,7 @@ Node classes
164166
Previous versions of Python allowed the creation of AST nodes that were missing
165167
required fields. Similarly, AST node constructors allowed arbitrary keyword
166168
arguments that were set as attributes of the AST node, even if they did not
167-
match any of the fields of the AST node. This behavior is deprecated and will
168-
be removed in Python 3.15.
169+
match any of the fields of the AST node. These cases now raise a :exc:`TypeError`.
169170

170171
.. note::
171172
The descriptions of the specific node classes displayed here

Doc/library/asyncio-task.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ Example::
394394
The ``async with`` statement will wait for all tasks in the group to finish.
395395
While waiting, new tasks may still be added to the group
396396
(for example, by passing ``tg`` into one of the coroutines
397-
and calling ``tg.create_task()`` in that coroutine). There is also opportunity
398-
to short-circuit the entire task group with ``tg.cancel()``, based on some condition.
397+
and calling ``tg.create_task()`` in that coroutine). There is also opportunity to
398+
request termination of the entire task group with ``tg.cancel()``, based on some condition.
399399
Once the last task has finished and the ``async with`` block is exited,
400400
no new tasks may be added to the group.
401401

Doc/library/contextlib.rst

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,40 @@ Functions and classes provided:
467467
statements. If this is not the case, then the original construct with the
468468
explicit :keyword:`!with` statement inside the function should be used.
469469

470+
When the decorated callable is a generator function, coroutine function, or
471+
asynchronous generator function, the returned wrapper is of the same kind
472+
and keeps the context manager open for the lifetime of the iteration or
473+
await rather than only for the call that creates the generator or coroutine
474+
object. Wrapped generators and asynchronous generators are explicitly
475+
closed when iteration ends, as if by :func:`closing` or :func:`aclosing`.
476+
477+
.. note::
478+
For asynchronous generators the wrapper re-yields each value with
479+
``async for``; values sent with :meth:`~agen.asend` and exceptions
480+
thrown with :meth:`~agen.athrow` are not forwarded to the wrapped
481+
generator.
482+
470483
.. versionadded:: 3.2
471484

485+
.. versionchanged:: next
486+
Decorating a generator function, coroutine function, or asynchronous
487+
generator function now keeps the context manager open across iteration
488+
or await. Previously the context manager exited as soon as the
489+
generator or coroutine object was created.
490+
472491

473492
.. class:: AsyncContextDecorator
474493

475-
Similar to :class:`ContextDecorator` but only for asynchronous functions.
494+
Similar to :class:`ContextDecorator`, but the context manager is entered
495+
and exited with :keyword:`async with`. Decorate coroutine functions and
496+
asynchronous generator functions with this class; the returned wrapper is
497+
of the same kind.
498+
499+
.. note::
500+
Synchronous functions and generators are accepted, but the wrapper is
501+
always asynchronous, so the decorated callable must then be awaited or
502+
iterated with ``async for``. If that change of calling convention is
503+
not intended, use :class:`ContextDecorator` instead.
476504

477505
Example of ``AsyncContextDecorator``::
478506

@@ -510,6 +538,13 @@ Functions and classes provided:
510538

511539
.. versionadded:: 3.10
512540

541+
.. versionchanged:: next
542+
Decorating an asynchronous generator function now keeps the context
543+
manager open across iteration. Previously the context manager exited
544+
as soon as the generator object was created. Synchronous functions
545+
and synchronous generator functions are also now accepted, with an
546+
asynchronous wrapper returned.
547+
513548

514549
.. class:: ExitStack()
515550

Doc/library/functions.rst

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ are always available. They are listed here in alphabetical order.
1919
| | :func:`ascii` | | :func:`filter` | | :func:`map` | | **S** |
2020
| | | | :func:`float` | | :func:`max` | | |func-set|_ |
2121
| | **B** | | :func:`format` | | |func-memoryview|_ | | :func:`setattr` |
22-
| | :func:`bin` | | |func-frozenset|_ | | :func:`min` | | :func:`slice` |
23-
| | :func:`bool` | | | | | | :func:`sorted` |
24-
| | :func:`breakpoint` | | **G** | | **N** | | :func:`staticmethod` |
25-
| | |func-bytearray|_ | | :func:`getattr` | | :func:`next` | | |func-str|_ |
26-
| | |func-bytes|_ | | :func:`globals` | | | | :func:`sum` |
27-
| | | | | | **O** | | :func:`super` |
28-
| | **C** | | **H** | | :func:`object` | | |
22+
| | :func:`bin` | | |func-frozenset|_ | | :func:`min` | | :func:`sentinel` |
23+
| | :func:`bool` | | | | | | :func:`slice` |
24+
| | :func:`breakpoint` | | **G** | | **N** | | :func:`sorted` |
25+
| | |func-bytearray|_ | | :func:`getattr` | | :func:`next` | | :func:`staticmethod` |
26+
| | |func-bytes|_ | | :func:`globals` | | | | |func-str|_ |
27+
| | | | | | **O** | | :func:`sum` |
28+
| | **C** | | **H** | | :func:`object` | | :func:`super` |
2929
| | :func:`callable` | | :func:`hasattr` | | :func:`oct` | | **T** |
3030
| | :func:`chr` | | :func:`hash` | | :func:`open` | | |func-tuple|_ |
3131
| | :func:`classmethod` | | :func:`help` | | :func:`ord` | | :func:`type` |
@@ -1827,6 +1827,61 @@ are always available. They are listed here in alphabetical order.
18271827
:func:`setattr`.
18281828

18291829

1830+
.. class:: sentinel(name, /)
1831+
1832+
Return a new unique sentinel object. *name* must be a :class:`str`, and is
1833+
used as the returned object's representation::
1834+
1835+
>>> MISSING = sentinel("MISSING")
1836+
>>> MISSING
1837+
MISSING
1838+
1839+
Sentinel objects are truthy and compare equal only to themselves. They are
1840+
intended to be compared with the :keyword:`is` operator.
1841+
1842+
Shallow and deep copies of a sentinel object return the object itself.
1843+
1844+
Sentinels are conventionally assigned to a variable with a matching name.
1845+
Sentinels defined in this way can be used in :term:`type hints <type hint>`::
1846+
1847+
MISSING = sentinel("MISSING")
1848+
1849+
def next_value(default: int | MISSING = MISSING):
1850+
...
1851+
1852+
Sentinel objects support the :ref:`| <bitwise>` operator for use in type expressions.
1853+
1854+
:mod:`Pickling <pickle>` is supported for sentinel objects that are
1855+
placed in the global scope of a module under a name matching the sentinel's
1856+
name, and for sentinels placed in class scopes with a name matching the
1857+
:term:`qualified name` of the sentinel. Other sentinels, such as those
1858+
defined in a function scope, are not picklable. The identity of the sentinel is preserved
1859+
after pickling::
1860+
1861+
import pickle
1862+
1863+
PICKLABLE = sentinel("PICKLABLE")
1864+
1865+
assert pickle.loads(pickle.dumps(PICKLABLE)) is PICKLABLE
1866+
1867+
class Cls:
1868+
PICKLABLE = sentinel("Cls.PICKLABLE")
1869+
1870+
assert pickle.loads(pickle.dumps(Cls.PICKLABLE)) is Cls.PICKLABLE
1871+
1872+
Sentinel objects have the following attributes:
1873+
1874+
.. attribute:: __name__
1875+
1876+
The sentinel's name.
1877+
1878+
.. attribute:: __module__
1879+
1880+
The name of the module where the sentinel was created.
1881+
1882+
.. versionadded:: next
1883+
1884+
18301885
.. class:: slice(stop, /)
18311886
slice(start, stop, step=None, /)
18321887

0 commit comments

Comments
 (0)