Skip to content

[3.13] gh-158254: Detect keys changing during reverse dict iteration (GH-158255) - #158269

Merged
ZeroIntensity merged 1 commit into
python:3.13from
miss-islington:backport-042a7c1-3.13
Sep 27, 2026
Merged

ZeroIntensity merged 1 commit into
python:3.13from
miss-islington:backport-042a7c1-3.13

Conversation

@miss-islington

@miss-islington miss-islington commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

A reverse dict iterator only checked that the dict's size was unchanged,
so after the keys were replaced with the same number of keys it kept
yielding entries for the new keys. It could yield more items than the
dict had when it was created, and length_hint() then wrapped around.

Add the check the forward iterators already have: finding an entry after
the expected number of items raises "dictionary keys changed during
iteration".
(cherry picked from commit 042a7c1)

Co-authored-by: Joshua Bronson jabronson@gmail.com
Co-authored-by: Claude Opus 5.5 noreply@anthropic.com

…ythonGH-158255)

A reverse dict iterator only checked that the dict's size was unchanged,
so after the keys were replaced with the same number of keys it kept
yielding entries for the new keys. It could yield more items than the
dict had when it was created, and __length_hint__() then wrapped around.

Add the check the forward iterators already have: finding an entry after
the expected number of items raises "dictionary keys changed during
iteration".
(cherry picked from commit 042a7c1)

Co-authored-by: Joshua Bronson <jabronson@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@ZeroIntensity
ZeroIntensity enabled auto-merge (squash) September 27, 2026 02:54
@ZeroIntensity
ZeroIntensity merged commit ff03e45 into python:3.13 Sep 27, 2026
44 checks passed
@miss-islington
miss-islington deleted the backport-042a7c1-3.13 branch September 27, 2026 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants