Skip to content

Commit 76077cd

Browse files
committed
Merge branch 'main' into inlinecomp2
* main: (47 commits) gh-97696 Remove unnecessary check for eager_start kwarg (#104188) GH-104308: socket.getnameinfo should release the GIL (#104307) gh-104310: Add importlib.util.allowing_all_extensions() (gh-104311) gh-99113: A Per-Interpreter GIL! (gh-104210) GH-104284: Fix documentation gettext build (#104296) gh-89550: Buffer GzipFile.write to reduce execution time by ~15% (#101251) gh-104223: Fix issues with inheriting from buffer classes (#104227) gh-99108: fix typo in Modules/Setup (#104293) GH-104145: Use fully-qualified cross reference types for the bisect module (#104172) gh-103193: Improve `getattr_static` test coverage (#104286) Trim trailing whitespace and test on CI (#104275) gh-102500: Remove mention of bytes shorthand (#104281) gh-97696: Improve and fix documentation for asyncio eager tasks (#104256) gh-99108: Replace SHA3 implementation HACL* version (#103597) gh-104273: Remove redundant len() calls in argparse function (#104274) gh-64660: Don't hardcode Argument Clinic return converter result variable name (#104200) gh-104265 Disallow instantiation of `_csv.Reader` and `_csv.Writer` (#104266) GH-102613: Improve performance of `pathlib.Path.rglob()` (GH-104244) gh-103650: Fix perf maps address format (#103651) GH-89812: Churn `pathlib.Path` methods (GH-104243) ...
2 parents ffae4e6 + bf89d42 commit 76077cd

File tree

147 files changed

+3589
-1549
lines changed

Some content is hidden

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

147 files changed

+3589
-1549
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
# GitHub
88
.github/** @ezio-melotti @hugovk
99

10+
# pre-commit
11+
.pre-commit-config.yaml @hugovk @AlexWaygood
12+
1013
# Build system
1114
configure* @erlend-aasland @corona10
1215

.github/workflows/lint.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Lint
2+
3+
on: [push, pull_request, workflow_dispatch]
4+
5+
permissions:
6+
contents: read
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
lint:
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 10
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- uses: actions/setup-python@v4
20+
with:
21+
python-version: "3.x"
22+
- uses: pre-commit/[email protected]

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: check-yaml
6+
- id: trailing-whitespace
7+
types_or: [c, python, rst]

Doc/c-api/dict.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Dictionary Objects
154154
155155
.. c:function:: Py_ssize_t PyDict_Size(PyObject *p)
156156
157-
.. index:: builtin: len
157+
.. index:: pair: built-in function; len
158158
159159
Return the number of items in the dictionary. This is equivalent to
160160
``len(p)`` on a dictionary.

Doc/c-api/import.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Importing Modules
4141
4242
.. c:function:: PyObject* PyImport_ImportModuleEx(const char *name, PyObject *globals, PyObject *locals, PyObject *fromlist)
4343
44-
.. index:: builtin: __import__
44+
.. index:: pair: built-in function; __import__
4545
4646
Import a module. This is best described by referring to the built-in Python
4747
function :func:`__import__`.
@@ -120,7 +120,7 @@ Importing Modules
120120
121121
.. c:function:: PyObject* PyImport_ExecCodeModule(const char *name, PyObject *co)
122122
123-
.. index:: builtin: compile
123+
.. index:: pair: built-in function; compile
124124
125125
Given a module name (possibly of the form ``package.module``) and a code object
126126
read from a Python bytecode file or obtained from the built-in function

Doc/c-api/list.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ List Objects
4545
4646
.. c:function:: Py_ssize_t PyList_Size(PyObject *list)
4747
48-
.. index:: builtin: len
48+
.. index:: pair: built-in function; len
4949
5050
Return the length of the list object in *list*; this is equivalent to
5151
``len(list)`` on a list object.
@@ -138,7 +138,7 @@ List Objects
138138
139139
.. c:function:: PyObject* PyList_AsTuple(PyObject *list)
140140
141-
.. index:: builtin: tuple
141+
.. index:: pair: built-in function; tuple
142142
143143
Return a new tuple object containing the contents of *list*; equivalent to
144144
``tuple(list)``.

Doc/c-api/mapping.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ See also :c:func:`PyObject_GetItem`, :c:func:`PyObject_SetItem` and
2020
.. c:function:: Py_ssize_t PyMapping_Size(PyObject *o)
2121
Py_ssize_t PyMapping_Length(PyObject *o)
2222
23-
.. index:: builtin: len
23+
.. index:: pair: built-in function; len
2424
2525
Returns the number of keys in object *o* on success, and ``-1`` on failure.
2626
This is equivalent to the Python expression ``len(o)``.

Doc/c-api/number.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ Number Protocol
6464
6565
.. c:function:: PyObject* PyNumber_Divmod(PyObject *o1, PyObject *o2)
6666
67-
.. index:: builtin: divmod
67+
.. index:: pair: built-in function; divmod
6868
6969
See the built-in function :func:`divmod`. Returns ``NULL`` on failure. This is
7070
the equivalent of the Python expression ``divmod(o1, o2)``.
7171
7272
7373
.. c:function:: PyObject* PyNumber_Power(PyObject *o1, PyObject *o2, PyObject *o3)
7474
75-
.. index:: builtin: pow
75+
.. index:: pair: built-in function; pow
7676
7777
See the built-in function :func:`pow`. Returns ``NULL`` on failure. This is the
7878
equivalent of the Python expression ``pow(o1, o2, o3)``, where *o3* is optional.
@@ -94,7 +94,7 @@ Number Protocol
9494
9595
.. c:function:: PyObject* PyNumber_Absolute(PyObject *o)
9696
97-
.. index:: builtin: abs
97+
.. index:: pair: built-in function; abs
9898
9999
Returns the absolute value of *o*, or ``NULL`` on failure. This is the equivalent
100100
of the Python expression ``abs(o)``.
@@ -192,7 +192,7 @@ Number Protocol
192192
193193
.. c:function:: PyObject* PyNumber_InPlacePower(PyObject *o1, PyObject *o2, PyObject *o3)
194194
195-
.. index:: builtin: pow
195+
.. index:: pair: built-in function; pow
196196
197197
See the built-in function :func:`pow`. Returns ``NULL`` on failure. The operation
198198
is done *in-place* when *o1* supports it. This is the equivalent of the Python
@@ -238,15 +238,15 @@ Number Protocol
238238
239239
.. c:function:: PyObject* PyNumber_Long(PyObject *o)
240240
241-
.. index:: builtin: int
241+
.. index:: pair: built-in function; int
242242
243243
Returns the *o* converted to an integer object on success, or ``NULL`` on
244244
failure. This is the equivalent of the Python expression ``int(o)``.
245245
246246
247247
.. c:function:: PyObject* PyNumber_Float(PyObject *o)
248248
249-
.. index:: builtin: float
249+
.. index:: pair: built-in function; float
250250
251251
Returns the *o* converted to a float object on success, or ``NULL`` on failure.
252252
This is the equivalent of the Python expression ``float(o)``.

Doc/c-api/object.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Object Protocol
190190
191191
.. c:function:: PyObject* PyObject_Repr(PyObject *o)
192192
193-
.. index:: builtin: repr
193+
.. index:: pair: built-in function; repr
194194
195195
Compute a string representation of object *o*. Returns the string
196196
representation on success, ``NULL`` on failure. This is the equivalent of the
@@ -202,7 +202,7 @@ Object Protocol
202202
203203
.. c:function:: PyObject* PyObject_ASCII(PyObject *o)
204204
205-
.. index:: builtin: ascii
205+
.. index:: pair: built-in function; ascii
206206
207207
As :c:func:`PyObject_Repr`, compute a string representation of object *o*, but
208208
escape the non-ASCII characters in the string returned by
@@ -227,7 +227,7 @@ Object Protocol
227227
228228
.. c:function:: PyObject* PyObject_Bytes(PyObject *o)
229229
230-
.. index:: builtin: bytes
230+
.. index:: pair: built-in function; bytes
231231
232232
Compute a bytes representation of object *o*. ``NULL`` is returned on
233233
failure and a bytes object on success. This is equivalent to the Python
@@ -278,7 +278,7 @@ Object Protocol
278278
279279
.. c:function:: Py_hash_t PyObject_Hash(PyObject *o)
280280
281-
.. index:: builtin: hash
281+
.. index:: pair: built-in function; hash
282282
283283
Compute and return the hash value of an object *o*. On failure, return ``-1``.
284284
This is the equivalent of the Python expression ``hash(o)``.
@@ -312,7 +312,7 @@ Object Protocol
312312
313313
.. c:function:: PyObject* PyObject_Type(PyObject *o)
314314
315-
.. index:: builtin: type
315+
.. index:: pair: built-in function; type
316316
317317
When *o* is non-``NULL``, returns a type object corresponding to the object type
318318
of object *o*. On failure, raises :exc:`SystemError` and returns ``NULL``. This
@@ -332,7 +332,7 @@ Object Protocol
332332
.. c:function:: Py_ssize_t PyObject_Size(PyObject *o)
333333
Py_ssize_t PyObject_Length(PyObject *o)
334334
335-
.. index:: builtin: len
335+
.. index:: pair: built-in function; len
336336
337337
Return the length of object *o*. If the object *o* provides either the sequence
338338
and mapping protocols, the sequence length is returned. On error, ``-1`` is

Doc/c-api/sequence.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Sequence Protocol
1818
.. c:function:: Py_ssize_t PySequence_Size(PyObject *o)
1919
Py_ssize_t PySequence_Length(PyObject *o)
2020
21-
.. index:: builtin: len
21+
.. index:: pair: built-in function; len
2222
2323
Returns the number of objects in sequence *o* on success, and ``-1`` on
2424
failure. This is equivalent to the Python expression ``len(o)``.
@@ -120,7 +120,7 @@ Sequence Protocol
120120
121121
.. c:function:: PyObject* PySequence_Tuple(PyObject *o)
122122
123-
.. index:: builtin: tuple
123+
.. index:: pair: built-in function; tuple
124124
125125
Return a tuple object with the same contents as the sequence or iterable *o*,
126126
or ``NULL`` on failure. If *o* is a tuple, a new reference will be returned,

Doc/c-api/set.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ or :class:`frozenset` or instances of their subtypes.
107107
108108
.. c:function:: Py_ssize_t PySet_Size(PyObject *anyset)
109109
110-
.. index:: builtin: len
110+
.. index:: pair: built-in function; len
111111
112112
Return the length of a :class:`set` or :class:`frozenset` object. Equivalent to
113113
``len(anyset)``. Raises a :exc:`PyExc_SystemError` if *anyset* is not a

Doc/c-api/structures.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ method.
347347
348348
.. data:: METH_CLASS
349349
350-
.. index:: builtin: classmethod
350+
.. index:: pair: built-in function; classmethod
351351
352352
The method will be passed the type object as the first parameter rather
353353
than an instance of the type. This is used to create *class methods*,
@@ -357,7 +357,7 @@ method.
357357
358358
.. data:: METH_STATIC
359359
360-
.. index:: builtin: staticmethod
360+
.. index:: pair: built-in function; staticmethod
361361
362362
The method will be passed ``NULL`` as the first parameter rather than an
363363
instance of the type. This is used to create *static methods*, similar to

Doc/c-api/typeobj.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ and :c:type:`PyType_Type` effectively act as defaults.)
805805

806806
.. c:member:: reprfunc PyTypeObject.tp_repr
807807
808-
.. index:: builtin: repr
808+
.. index:: pair: built-in function; repr
809809

810810
An optional pointer to a function that implements the built-in function
811811
:func:`repr`.
@@ -870,7 +870,7 @@ and :c:type:`PyType_Type` effectively act as defaults.)
870870

871871
.. c:member:: hashfunc PyTypeObject.tp_hash
872872
873-
.. index:: builtin: hash
873+
.. index:: pair: built-in function; hash
874874

875875
An optional pointer to a function that implements the built-in function
876876
:func:`hash`.

Doc/extending/newtypes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ done. This can be done using the :c:func:`PyErr_Fetch` and
149149

150150
.. index::
151151
single: string; object representation
152-
builtin: repr
152+
pair: built-in function; repr
153153

154154
Object Presentation
155155
-------------------

Doc/library/asyncio-task.rst

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,13 @@ Eager Task Factory
560560
using the provided *custom_task_constructor* when creating a new task instead
561561
of the default :class:`Task`.
562562

563+
*custom_task_constructor* must be a *callable* with the signature matching
564+
the signature of :class:`Task.__init__ <Task>`.
565+
The callable must return a :class:`asyncio.Task`-compatible object.
566+
567+
This function returns a *callable* intended to be used as a task factory of an
568+
event loop via :meth:`loop.set_task_factory(factory) <loop.set_task_factory>`).
569+
563570
.. versionadded:: 3.12
564571

565572

@@ -1014,7 +1021,7 @@ Introspection
10141021
Task Object
10151022
===========
10161023

1017-
.. class:: Task(coro, *, loop=None, name=None)
1024+
.. class:: Task(coro, *, loop=None, name=None, context=None, eager_start=False)
10181025

10191026
A :class:`Future-like <Future>` object that runs a Python
10201027
:ref:`coroutine <coroutine>`. Not thread-safe.
@@ -1049,9 +1056,17 @@ Task Object
10491056
APIs except :meth:`Future.set_result` and
10501057
:meth:`Future.set_exception`.
10511058

1052-
Tasks support the :mod:`contextvars` module. When a Task
1053-
is created it copies the current context and later runs its
1054-
coroutine in the copied context.
1059+
An optional keyword-only *context* argument allows specifying a
1060+
custom :class:`contextvars.Context` for the *coro* to run in.
1061+
If no *context* is provided, the Task copies the current context
1062+
and later runs its coroutine in the copied context.
1063+
1064+
An optional keyword-only *eager_start* argument allows eagerly starting
1065+
the execution of the :class:`asyncio.Task` at task creation time.
1066+
If set to ``True`` and the event loop is running, the task will start
1067+
executing the coroutine immediately, until the first time the coroutine
1068+
blocks. If the coroutine returns or raises without blocking, the task
1069+
will be finished eagerly and will skip scheduling to the event loop.
10551070

10561071
.. versionchanged:: 3.7
10571072
Added support for the :mod:`contextvars` module.
@@ -1063,6 +1078,12 @@ Task Object
10631078
Deprecation warning is emitted if *loop* is not specified
10641079
and there is no running event loop.
10651080

1081+
.. versionchanged:: 3.11
1082+
Added the *context* parameter.
1083+
1084+
.. versionchanged:: 3.12
1085+
Added the *eager_start* parameter.
1086+
10661087
.. method:: done()
10671088

10681089
Return ``True`` if the Task is *done*.

0 commit comments

Comments
 (0)