@@ -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+
156180PEP 688: Making the buffer protocol accessible in Python
157181--------------------------------------------------------
158182
0 commit comments