Skip to content

Commit a614216

Browse files
committed
Merge branch 'main' into fixsendfamily
* main: (29 commits) pythongh-104276: Make `_struct.unpack_iterator` type use type flag instead of custom constructor (python#104277) pythongh-97696: Move around and update the whatsnew entry for asyncio eager task factory (python#104298) pythongh-103193: Fix refleaks in `test_inspect` and `test_typing` (python#104320) require-pr-label.yml: Add missing "permissions:" (python#104309) pythongh-90656: Add platform triplets for 64-bit LoongArch (LA64) (python#30939) pythongh-104180: Read SOCKS proxies from macOS System Configuration (python#104181) pythongh-97696 Remove unnecessary check for eager_start kwarg (python#104188) pythonGH-104308: socket.getnameinfo should release the GIL (python#104307) pythongh-104310: Add importlib.util.allowing_all_extensions() (pythongh-104311) pythongh-99113: A Per-Interpreter GIL! (pythongh-104210) pythonGH-104284: Fix documentation gettext build (python#104296) pythongh-89550: Buffer GzipFile.write to reduce execution time by ~15% (python#101251) pythongh-104223: Fix issues with inheriting from buffer classes (python#104227) pythongh-99108: fix typo in Modules/Setup (python#104293) pythonGH-104145: Use fully-qualified cross reference types for the bisect module (python#104172) pythongh-103193: Improve `getattr_static` test coverage (python#104286) Trim trailing whitespace and test on CI (python#104275) pythongh-102500: Remove mention of bytes shorthand (python#104281) pythongh-97696: Improve and fix documentation for asyncio eager tasks (python#104256) pythongh-99108: Replace SHA3 implementation HACL* version (python#103597) ...
2 parents 6b0d946 + c21f828 commit a614216

File tree

92 files changed

+2509
-995
lines changed

Some content is hidden

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

92 files changed

+2509
-995
lines changed

.github/CODEOWNERS

+3
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

+22
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/action@v3.0.0

.github/workflows/require-pr-label.yml

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ on:
44
pull_request:
55
types: [opened, reopened, labeled, unlabeled, synchronize]
66

7+
permissions:
8+
issues: read
9+
pull-requests: read
10+
711
jobs:
812
label:
913
name: DO-NOT-MERGE / unresolved review

.pre-commit-config.yaml

+7
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/library/asyncio-task.rst

+18-1
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, context=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.
@@ -1054,6 +1061,13 @@ Task Object
10541061
If no *context* is provided, the Task copies the current context
10551062
and later runs its coroutine in the copied context.
10561063

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.
1070+
10571071
.. versionchanged:: 3.7
10581072
Added support for the :mod:`contextvars` module.
10591073

@@ -1067,6 +1081,9 @@ Task Object
10671081
.. versionchanged:: 3.11
10681082
Added the *context* parameter.
10691083

1084+
.. versionchanged:: 3.12
1085+
Added the *eager_start* parameter.
1086+
10701087
.. method:: done()
10711088

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

Doc/library/bisect.rst

+12-10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ method to determine whether a value has been found. Instead, the
2424
functions only call the :meth:`__lt__` method and will return an insertion
2525
point between values in an array.
2626

27+
.. _bisect functions:
28+
2729
The following functions are provided:
2830

2931

@@ -55,7 +57,7 @@ The following functions are provided:
5557
.. function:: bisect_right(a, x, lo=0, hi=len(a), *, key=None)
5658
bisect(a, x, lo=0, hi=len(a), *, key=None)
5759
58-
Similar to :func:`bisect_left`, but returns an insertion point which comes
60+
Similar to :py:func:`~bisect.bisect_left`, but returns an insertion point which comes
5961
after (to the right of) any existing entries of *x* in *a*.
6062

6163
The returned insertion point *ip* partitions the array *a* into two slices
@@ -70,7 +72,7 @@ The following functions are provided:
7072

7173
Insert *x* in *a* in sorted order.
7274

73-
This function first runs :func:`bisect_left` to locate an insertion point.
75+
This function first runs :py:func:`~bisect.bisect_left` to locate an insertion point.
7476
Next, it runs the :meth:`insert` method on *a* to insert *x* at the
7577
appropriate position to maintain sort order.
7678

@@ -87,10 +89,10 @@ The following functions are provided:
8789
.. function:: insort_right(a, x, lo=0, hi=len(a), *, key=None)
8890
insort(a, x, lo=0, hi=len(a), *, key=None)
8991
90-
Similar to :func:`insort_left`, but inserting *x* in *a* after any existing
92+
Similar to :py:func:`~bisect.insort_left`, but inserting *x* in *a* after any existing
9193
entries of *x*.
9294

93-
This function first runs :func:`bisect_right` to locate an insertion point.
95+
This function first runs :py:func:`~bisect.bisect_right` to locate an insertion point.
9496
Next, it runs the :meth:`insert` method on *a* to insert *x* at the
9597
appropriate position to maintain sort order.
9698

@@ -120,7 +122,7 @@ thoughts in mind:
120122
they are used. Consequently, if the search functions are used in a loop,
121123
the key function may be called again and again on the same array elements.
122124
If the key function isn't fast, consider wrapping it with
123-
:func:`functools.cache` to avoid duplicate computations. Alternatively,
125+
:py:func:`functools.cache` to avoid duplicate computations. Alternatively,
124126
consider searching an array of precomputed keys to locate the insertion
125127
point (as shown in the examples section below).
126128

@@ -140,7 +142,7 @@ thoughts in mind:
140142
Searching Sorted Lists
141143
----------------------
142144

143-
The above :func:`bisect` functions are useful for finding insertion points but
145+
The above `bisect functions`_ are useful for finding insertion points but
144146
can be tricky or awkward to use for common searching tasks. The following five
145147
functions show how to transform them into the standard lookups for sorted
146148
lists::
@@ -186,8 +188,8 @@ Examples
186188

187189
.. _bisect-example:
188190

189-
The :func:`bisect` function can be useful for numeric table lookups. This
190-
example uses :func:`bisect` to look up a letter grade for an exam score (say)
191+
The :py:func:`~bisect.bisect` function can be useful for numeric table lookups. This
192+
example uses :py:func:`~bisect.bisect` to look up a letter grade for an exam score (say)
191193
based on a set of ordered numeric breakpoints: 90 and up is an 'A', 80 to 89 is
192194
a 'B', and so on::
193195

@@ -198,8 +200,8 @@ a 'B', and so on::
198200
>>> [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]]
199201
['F', 'A', 'C', 'C', 'B', 'A', 'A']
200202

201-
The :func:`bisect` and :func:`insort` functions also work with lists of
202-
tuples. The *key* argument can serve to extract the field used for ordering
203+
The :py:func:`~bisect.bisect` and :py:func:`~bisect.insort` functions also work with
204+
lists of tuples. The *key* argument can serve to extract the field used for ordering
203205
records in a table::
204206

205207
>>> from collections import namedtuple

Doc/library/typing.rst

+3-6
Original file line numberDiff line numberDiff line change
@@ -2130,15 +2130,10 @@ Corresponding to collections in :mod:`collections.abc`
21302130

21312131
.. class:: ByteString(Sequence[int])
21322132

2133-
A generic version of :class:`collections.abc.ByteString`.
2134-
21352133
This type represents the types :class:`bytes`, :class:`bytearray`,
21362134
and :class:`memoryview` of byte sequences.
21372135

2138-
As a shorthand for this type, :class:`bytes` can be used to
2139-
annotate arguments of any of the types mentioned above.
2140-
2141-
.. deprecated:: 3.9
2136+
.. deprecated-removed:: 3.9 3.14
21422137
Prefer :class:`collections.abc.Buffer`, or a union like ``bytes | bytearray | memoryview``.
21432138

21442139
.. class:: Collection(Sized, Iterable[T_co], Container[T_co])
@@ -2977,6 +2972,8 @@ convenience. This is subject to change, and not all deprecations are listed.
29772972
| ``typing`` versions of standard | 3.9 | Undecided | :pep:`585` |
29782973
| collections | | | |
29792974
+----------------------------------+---------------+-------------------+----------------+
2975+
| ``typing.ByteString`` | 3.9 | 3.14 | :gh:`91896` |
2976+
+----------------------------------+---------------+-------------------+----------------+
29802977
| ``typing.Text`` | 3.11 | Undecided | :gh:`92332` |
29812978
+----------------------------------+---------------+-------------------+----------------+
29822979
| ``typing.Hashable`` and | 3.12 | Undecided | :gh:`94309` |

Doc/tools/extensions/pyspecific.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,14 @@ def process_audit_events(app, doctree, fromdocname):
674674
node.replace_self(table)
675675

676676

677-
def patch_pairindextypes(app) -> None:
677+
def patch_pairindextypes(app, _env) -> None:
678+
"""Remove all entries from ``pairindextypes`` before writing POT files.
679+
680+
We want to run this just before writing output files, as the check to
681+
circumvent is in ``I18nBuilder.write_doc()``.
682+
As such, we link this to ``env-check-consistency``, even though it has
683+
nothing to do with the environment consistency check.
684+
"""
678685
if app.builder.name != 'gettext':
679686
return
680687

@@ -688,14 +695,7 @@ def patch_pairindextypes(app) -> None:
688695
# the Sphinx-translated pairindextypes values. As we intend to move
689696
# away from this, we need Sphinx to believe that these values don't
690697
# exist, by deleting them when using the gettext builder.
691-
692-
pairindextypes.pop('module', None)
693-
pairindextypes.pop('keyword', None)
694-
pairindextypes.pop('operator', None)
695-
pairindextypes.pop('object', None)
696-
pairindextypes.pop('exception', None)
697-
pairindextypes.pop('statement', None)
698-
pairindextypes.pop('builtin', None)
698+
pairindextypes.clear()
699699

700700

701701
def setup(app):
@@ -719,7 +719,7 @@ def setup(app):
719719
app.add_directive_to_domain('py', 'awaitablemethod', PyAwaitableMethod)
720720
app.add_directive_to_domain('py', 'abstractmethod', PyAbstractMethod)
721721
app.add_directive('miscnews', MiscNews)
722-
app.connect('builder-inited', patch_pairindextypes)
722+
app.connect('env-check-consistency', patch_pairindextypes)
723723
app.connect('doctree-resolved', process_audit_events)
724724
app.connect('env-merge-info', audit_events_merge)
725725
app.connect('env-purge-doc', audit_events_purge)

Doc/whatsnew/3.12.rst

+17-8
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ asyncio
282282
writing to sockets and uses :meth:`~socket.socket.sendmsg` if the platform
283283
supports it. (Contributed by Kumar Aditya in :gh:`91166`.)
284284

285+
* Added :func:`asyncio.eager_task_factory` and :func:`asyncio.create_eager_task_factory`
286+
functions to allow opting an event loop in to eager task execution,
287+
making some use-cases 2x to 5x faster.
288+
(Contributed by Jacob Bower & Itamar O in :gh:`102853`, :gh:`104140`, and :gh:`104138`)
289+
285290
* On Linux, :mod:`asyncio` uses :class:`~asyncio.PidfdChildWatcher` by default
286291
if :func:`os.pidfd_open` is available and functional instead of
287292
:class:`~asyncio.ThreadedChildWatcher`.
@@ -342,8 +347,9 @@ inspect
342347
(Contributed by Thomas Krennwallner in :issue:`35759`.)
343348

344349
* The performance of :func:`inspect.getattr_static` has been considerably
345-
improved. Most calls to the function should be around 2x faster than they
346-
were in Python 3.11. (Contributed by Alex Waygood in :gh:`103193`.)
350+
improved. Most calls to the function should be at least 2x faster than they
351+
were in Python 3.11, and some may be 6x faster or more. (Contributed by Alex
352+
Waygood in :gh:`103193`.)
347353

348354
pathlib
349355
-------
@@ -597,7 +603,7 @@ typing
597603
:func:`runtime-checkable protocols <typing.runtime_checkable>` has changed
598604
significantly. Most ``isinstance()`` checks against protocols with only a few
599605
members should be at least 2x faster than in 3.11, and some may be 20x
600-
faster or more. However, ``isinstance()`` checks against protocols with seven
606+
faster or more. However, ``isinstance()`` checks against protocols with fourteen
601607
or more members may be slower than in Python 3.11. (Contributed by Alex
602608
Waygood in :gh:`74690` and :gh:`103193`.)
603609

@@ -643,11 +649,6 @@ Optimizations
643649
* Speed up :class:`asyncio.Task` creation by deferring expensive string formatting.
644650
(Contributed by Itamar O in :gh:`103793`.)
645651

646-
* Added :func:`asyncio.eager_task_factory` and :func:`asyncio.create_eager_task_factory`
647-
functions to allow opting an event loop in to eager task execution,
648-
speeding up some use-cases by up to 50%.
649-
(Contributed by Jacob Bower & Itamar O in :gh:`102853`)
650-
651652

652653
CPython bytecode changes
653654
========================
@@ -1168,6 +1169,14 @@ Build Changes
11681169
optimization levels (0, 1, 2) at once.
11691170
(Contributed by Victor Stinner in :gh:`99289`.)
11701171

1172+
* Add platform triplets for 64-bit LoongArch:
1173+
1174+
* loongarch64-linux-gnusf
1175+
* loongarch64-linux-gnuf32
1176+
* loongarch64-linux-gnu
1177+
1178+
(Contributed by Zhang Na in :gh:`90656`.)
1179+
11711180

11721181
C API Changes
11731182
=============

Include/cpython/memoryobject.h

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ typedef struct {
2424
#define _Py_MEMORYVIEW_FORTRAN 0x004 /* Fortran contiguous layout */
2525
#define _Py_MEMORYVIEW_SCALAR 0x008 /* scalar: ndim = 0 */
2626
#define _Py_MEMORYVIEW_PIL 0x010 /* PIL-style layout */
27+
#define _Py_MEMORYVIEW_RESTRICTED 0x020 /* Disallow new references to the memoryview's buffer */
2728

2829
typedef struct {
2930
PyObject_VAR_HEAD

Include/internal/pycore_ceval.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ struct _ceval_runtime_state;
2121

2222

2323
extern void _Py_FinishPendingCalls(PyThreadState *tstate);
24-
extern void _PyEval_InitRuntimeState(struct _ceval_runtime_state *);
25-
extern void _PyEval_InitState(struct _ceval_state *, PyThread_type_lock);
24+
extern void _PyEval_InitState(PyInterpreterState *, PyThread_type_lock);
2625
extern void _PyEval_FiniState(struct _ceval_state *ceval);
2726
PyAPI_FUNC(void) _PyEval_SignalReceived(PyInterpreterState *interp);
2827
PyAPI_FUNC(int) _PyEval_AddPendingCall(

Include/internal/pycore_ceval_state.h

-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ struct _ceval_runtime_state {
4949
the main thread of the main interpreter can handle signals: see
5050
_Py_ThreadCanHandleSignals(). */
5151
_Py_atomic_int signals_pending;
52-
53-
/* This is (only) used indirectly through PyInterpreterState.ceval.gil. */
54-
struct _gil_runtime_state gil;
5552
};
5653

5754
#ifdef PY_HAVE_PERF_TRAMPOLINE

Include/internal/pycore_compile.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ PyAPI_FUNC(PyObject*) _PyCompile_CodeGen(
9797
PyObject *ast,
9898
PyObject *filename,
9999
PyCompilerFlags *flags,
100-
int optimize);
100+
int optimize,
101+
int compile_mode);
101102

102103
PyAPI_FUNC(PyObject*) _PyCompile_OptimizeCfg(
103104
PyObject *instructions,

Include/internal/pycore_global_objects_fini_generated.h

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

+1
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ struct _Py_global_strings {
335335
STRUCT_FOR_ID(code)
336336
STRUCT_FOR_ID(command)
337337
STRUCT_FOR_ID(comment_factory)
338+
STRUCT_FOR_ID(compile_mode)
338339
STRUCT_FOR_ID(consts)
339340
STRUCT_FOR_ID(context)
340341
STRUCT_FOR_ID(cookie)

Include/internal/pycore_interp.h

+3
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ struct _is {
178178
basis. Also see _PyRuntimeState regarding the various mutex fields.
179179
*/
180180

181+
/* The per-interpreter GIL, which might not be used. */
182+
struct _gil_runtime_state _gil;
183+
181184
/* the initial PyInterpreterState.threads.head */
182185
PyThreadState _initial_thread;
183186
};

Include/internal/pycore_memoryobject.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ extern "C" {
99
#endif
1010

1111
PyObject *
12-
PyMemoryView_FromObjectAndFlags(PyObject *v, int flags);
12+
_PyMemoryView_FromBufferProc(PyObject *v, int flags,
13+
getbufferproc bufferproc);
1314

1415
#ifdef __cplusplus
1516
}

Include/internal/pycore_runtime.h

-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ struct _getargs_runtime_state {
3232
struct _PyArg_Parser *static_parsers;
3333
};
3434

35-
/* ceval state */
36-
3735
/* GIL state */
3836

3937
struct _gilstate_runtime_state {

Include/internal/pycore_runtime_init_generated.h

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)