Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 13aefd1

Browse files
authored
gh-105256: What's New note for comprehension over locals() (#106378)
1 parent 104d7b7 commit 13aefd1

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)