8000 gh-105256: What's New note for comprehension over locals() · carljm/cpython@3afb538 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3afb538

Browse files
committed
pythongh-105256: What's New note for comprehension over locals()
1 parent 71b4044 commit 3afb538

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Doc/whatsnew/3.12.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ 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 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 shown by e.g. ``for k in locals():``. To avoid the error, first create
260+
a list of keys to iterate over: ``keys = list(locals()); [k for k in keys]``.
256261

257262
Contributed by Carl Meyer and Vladimir Matveev in :pep:`709`.
258263

0 commit comments

Comments
 (0)
0