Skip to content

Commit 9ca079f

Browse files
Pull in main
2 parents 314137f + 22f3425 commit 9ca079f

Some content is hidden

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

48 files changed

+1497
-778
lines changed

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

Lines changed: 4 additions & 0 deletions
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

Doc/library/asyncio-task.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,8 @@ Running Tasks Concurrently
527527
and there is no running event loop.
528528

529529

530+
.. _eager-task-factory:
531+
530532
Eager Task Factory
531533
==================
532534

@@ -1174,8 +1176,17 @@ Task Object
11741176

11751177
Return the coroutine object wrapped by the :class:`Task`.
11761178

1179+
.. note::
1180+
1181+
This will return ``None`` for Tasks which have already
1182+
completed eagerly. See the :ref:`Eager Task Factory <eager-task-factory>`.
1183+
11771184
.. versionadded:: 3.8
11781185

1186+
.. versionchanged:: 3.12
1187+
1188+
Newly added eager task execution means result may be ``None``.
1189+
11791190
.. method:: get_context()
11801191

11811192
Return the :class:`contextvars.Context` object

Doc/library/dis.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,14 @@ iterations of the loop.
11961196

11971197
.. versionadded:: 3.12
11981198

1199+
.. opcode:: LOAD_FAST_AND_CLEAR (var_num)
1200+
1201+
Pushes a reference to the local ``co_varnames[var_num]`` onto the stack (or
1202+
pushes ``NULL`` onto the stack if the local variable has not been
1203+
initialized) and sets ``co_varnames[var_num]`` to ``NULL``.
1204+
1205+
.. versionadded:: 3.12
1206+
11991207
.. opcode:: STORE_FAST (var_num)
12001208

12011209
Stores ``STACK.pop()`` into the local ``co_varnames[var_num]``.

Doc/library/http.client.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ HTTPConnection Objects
264264
encode_chunked=False)
265265

266266
This will send a request to the server using the HTTP request
267-
method *method* and the selector *url*.
267+
method *method* and the request URI *url*. The provided *url* must be
268+
an absolute path to conform with :rfc:`RFC 2616 §5.1.2 <2616#section-5.1.2>`
269+
(unless connecting to an HTTP proxy server or using the ``OPTIONS`` or
270+
``CONNECT`` methods).
268271

269272
If *body* is specified, the specified data is sent after the headers are
270273
finished. It may be a :class:`str`, a :term:`bytes-like object`, an
@@ -279,7 +282,10 @@ HTTPConnection Objects
279282
iterable are sent as is until the iterable is exhausted.
280283

281284
The *headers* argument should be a mapping of extra HTTP headers to send
282-
with the request.
285+
with the request. A :rfc:`Host header <2616#section-14.23>`
286+
must be provided to conform with :rfc:`RFC 2616 §5.1.2 <2616#section-5.1.2>`
287+
(unless connecting to an HTTP proxy server or using the ``OPTIONS`` or
288+
``CONNECT`` methods).
283289

284290
If *headers* contains neither Content-Length nor Transfer-Encoding,
285291
but there is a request body, one of those
@@ -298,6 +304,16 @@ HTTPConnection Objects
298304
HTTPConnection object assumes that all encoding is handled by the
299305
calling code. If it is ``True``, the body will be chunk-encoded.
300306

307+
For example, to perform a ``GET`` request to ``https://docs.python.org/3/``::
308+
309+
>>> import http.client
310+
>>> host = "docs.python.org"
311+
>>> conn = http.client.HTTPSConnection(host)
312+
>>> conn.request("GET", "/3/", headers={"Host": host})
313+
>>> response = conn.getresponse()
314+
>>> print(response.status, response.reason)
315+
200 OK
316+
301317
.. note::
302318
Chunked transfer encoding has been added to the HTTP protocol
303319
version 1.1. Unless the HTTP server is known to handle HTTP 1.1,

Doc/whatsnew/3.12.rst

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,30 @@ New Features
153153
In Python 3.14, the default will switch to ``'data'``.
154154
(Contributed by Petr Viktorin in :pep:`706`.)
155155

156+
.. _whatsnew312-pep709:
157+
158+
PEP 709: Comprehension inlining
159+
-------------------------------
160+
161+
Dictionary, list, and set comprehensions are now inlined, rather than creating a
162+
new single-use function object for each execution of the comprehension. This
163+
speeds up execution of a comprehension by up to 2x.
164+
165+
Comprehension iteration variables remain isolated; they don't overwrite a
166+
variable of the same name in the outer scope, nor are they visible after the
167+
comprehension. This isolation is now maintained via stack/locals manipulation,
168+
not via separate function scope.
169+
170+
Inlining does result in a few visible behavior changes:
171+
172+
* There is no longer a separate frame for the comprehension in tracebacks,
173+
and tracing/profiling no longer shows the comprehension as a function call.
174+
* Calling :func:`locals` inside a comprehension now includes variables
175+
from outside the comprehension, and no longer includes the synthetic ``.0``
176+
variable for the comprehension "argument".
177+
178+
Contributed by Carl Meyer and Vladimir Matveev in :pep:`709`.
179+
156180
PEP 688: Making the buffer protocol accessible in Python
157181
--------------------------------------------------------
158182

@@ -282,6 +306,11 @@ asyncio
282306
writing to sockets and uses :meth:`~socket.socket.sendmsg` if the platform
283307
supports it. (Contributed by Kumar Aditya in :gh:`91166`.)
284308

309+
* Added :func:`asyncio.eager_task_factory` and :func:`asyncio.create_eager_task_factory`
310+
functions to allow opting an event loop in to eager task execution,
311+
making some use-cases 2x to 5x faster.
312+
(Contributed by Jacob Bower & Itamar O in :gh:`102853`, :gh:`104140`, and :gh:`104138`)
313+
285314
* On Linux, :mod:`asyncio` uses :class:`~asyncio.PidfdChildWatcher` by default
286315
if :func:`os.pidfd_open` is available and functional instead of
287316
:class:`~asyncio.ThreadedChildWatcher`.
@@ -644,11 +673,6 @@ Optimizations
644673
* Speed up :class:`asyncio.Task` creation by deferring expensive string formatting.
645674
(Contributed by Itamar O in :gh:`103793`.)
646675

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

653677
CPython bytecode changes
654678
========================

Include/internal/pycore_code.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ struct callable_cache {
131131
// Note that these all fit within a byte, as do combinations.
132132
// Later, we will use the smaller numbers to differentiate the different
133133
// kinds of locals (e.g. pos-only arg, varkwargs, local-only).
134+
#define CO_FAST_HIDDEN 0x10
134135
#define CO_FAST_LOCAL 0x20
135136
#define CO_FAST_CELL 0x40
136137
#define CO_FAST_FREE 0x80

Include/internal/pycore_compile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ typedef struct {
7070
PyObject *u_varnames; /* local variables */
7171
PyObject *u_cellvars; /* cell variables */
7272
PyObject *u_freevars; /* free variables */
73+
PyObject *u_fasthidden; /* dict; keys are names that are fast-locals only
74+
temporarily within an inlined comprehension. When
75+
value is True, treat as fast-local. */
7376

7477
Py_ssize_t u_argcount; /* number of arguments for block */
7578
Py_ssize_t u_posonlyargcount; /* number of positional only arguments for block */

Include/internal/pycore_flowgraph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ _PyCfgInstruction* _PyCfg_BasicblockLastInstr(const _PyCfgBasicblock *b);
9494
int _PyCfg_OptimizeCodeUnit(_PyCfgBuilder *g, PyObject *consts, PyObject *const_cache,
9595
int code_flags, int nlocals, int nparams, int firstlineno);
9696
int _PyCfg_Stackdepth(_PyCfgBasicblock *entryblock, int code_flags);
97-
void _PyCfg_ConvertExceptionHandlersToNops(_PyCfgBasicblock *entryblock);
97+
void _PyCfg_ConvertPseudoOps(_PyCfgBasicblock *entryblock);
9898
int _PyCfg_ResolveJumps(_PyCfgBuilder *g);
9999

100100

Include/internal/pycore_opcode.h

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_symtable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ typedef struct _symtable_entry {
6464
unsigned ste_needs_class_closure : 1; /* for class scopes, true if a
6565
closure over __class__
6666
should be created */
67+
unsigned ste_comp_inlined : 1; /* true if this comprehension is inlined */
6768
unsigned ste_comp_iter_target : 1; /* true if visiting comprehension target */
6869
int ste_comp_iter_expr; /* non-zero if visiting a comprehension range expression */
6970
int ste_lineno; /* first line of block */

0 commit comments

Comments
 (0)