Skip to content

Commit 1e4c235

Browse files
[3.12] gh-105256: What's New note for comprehension over locals() (GH-106378) (#106471)
gh-105256: What's New note for comprehension over locals() (GH-106378) (cherry picked from commit 13aefd1) Co-authored-by: Carl Meyer <[email protected]>
1 parent 7b615a1 commit 1e4c235

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Doc/whatsnew/3.12.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@ Inlining does result in a few visible behavior changes:
253253
* Calling :func:`locals` inside a comprehension now includes variables
254254
from outside the comprehension, and no longer includes the synthetic ``.0``
255255
variable for the comprehension "argument".
256+
* A comprehension iterating directly over ``locals()`` (e.g. ``[k for k in
257+
locals()]``) may see "RuntimeError: dictionary changed size during iteration"
258+
when run under tracing (e.g. code coverage measurement). This is the same
259+
behavior already seen in e.g. ``for k in locals():``. To avoid the error, first
260+
create a list of keys to iterate over: ``keys = list(locals()); [k for k in
261+
keys]``.
256262

257263
Contributed by Carl Meyer and Vladimir Matveev in :pep:`709`.
258264

0 commit comments

Comments
 (0)