Repository navigation
Avoid quadratic == in Traceback.recursionindex - #15460
Draft
RonnyPfannschmidt wants to merge 2 commits into
Draft
RonnyPfannschmidt wants to merge 2 commits into
RonnyPfannschmidt wants to merge 2 commits into
Conversation
Traceback.recursionindex() compared the locals of every pair of frames at the same position with ==. With many distinct objects whose == is expensive, such as MagicMock chains, this was quadratic and made pytest hang (and run out of memory) while reporting a RecursionError. Add a signature of the locals' hashes (None for unhashable values) to the cache key, so frames whose locals differ in hash are never compared. == still decides within a bucket, so hash collisions stay correct. Fixes #8482. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014GZsREz8Phxxsz95jUvKhC
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014GZsREz8Phxxsz95jUvKhC
RonnyPfannschmidt
requested review from
bluetech and
nicoddemus
and removed request for
nicoddemus
November 25, 2026 20:48
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Ronny · project thread
🤖 Written by Claude Opus 5.5 via Claude Code for the pytest maintainers; I prompted it, it did the work, I read it.
Fixes #8482.
recursionindex()compared all frame locals at the same position pairwise with==, which hangs on MagicMock chains; this adds a tuple of the locals' hashes (None if unhashable) to the cache key so only hash-equal frames get compared, and==still decides. Trade-off: objects whose__eq__disagrees with__hash__(e.g. value__eq__with identity hash) or a local switching betweensetand an equalfrozensetare no longer matched; those cases fall back to the existing first/last-10-frames view.Generated by Claude Code