8000 Merge branch 'main' into fixsendfamily · carljm/cpython@e40071d · GitHub
[go: up one dir, main page]

Skip to content

Commit e40071d

Browse files
committed
Merge branch 'main' into fixsendfamily
* main: pythongh-97696 Add documentation for get_coro() behavior with eager tasks (python#104304) pythongh-97933: (PEP 709) inline list/dict/set comprehensions (python#101441) pythongh-99889: Fix directory traversal security flaw in uu.decode() (python#104096) pythongh-104184: fix building --with-pydebug --enable-pystats (python#104217) pythongh-104139: Add itms-services to uses_netloc urllib.parse. (python#104312) pythongh-104240: return code unit metadata from codegen (python#104300)
2 parents f44e763 + 2866e03 commit e40071d

36 files changed

+1366
-718
lines changed

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/whatsnew/3.12.rst

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

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< F987 /code>

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 */

Include/opcode.h

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

Lib/importlib/_bootstrap_external.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ def _write_atomic(path, data, mode=0o666):
442442
# Python 3.12b1 3526 (Add instrumentation support)
443443
# Python 3.12b1 3527 (Add LOAD_SUPER_ATTR)
444444
# Python 3.12b1 3528 (Add LOAD_SUPER_ATTR_METHOD specialization)
445+
# Python 3.12b1 3529 (Inline list/dict/set comprehensions)
445446

446447
# Python 3.13 will start with 3550
447448

68CD
@@ -458,7 +459,7 @@ def _write_atomic(path, data, mode=0o666):
458459
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
459460
# in PC/launcher.c must also be updated.
460461

461-
MAGIC_NUMBER = (3528).to_bytes(2, 'little') + b'\r\n'
462+
MAGIC_NUMBER = (3529).to_bytes(2, 'little') + b'\r\n'
462463

463464
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
464465

0 commit comments

Comments
 (0)
0