Skip to content

Avoid quadratic == in Traceback.recursionindex - #15460

Draft
RonnyPfannschmidt wants to merge 2 commits into
mainfrom
claude/project-thread-kjpf24
Draft

RonnyPfannschmidt wants to merge 2 commits into
mainfrom
claude/project-thread-kjpf24

Conversation

@RonnyPfannschmidt

Copy link
Copy Markdown
Member

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 between set and an equal frozenset are no longer matched; those cases fall back to the existing first/last-10-frames view.


Generated by Claude Code

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
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Nov 25, 2026
@RonnyPfannschmidt RonnyPfannschmidt self-assigned this Nov 25, 2026
@RonnyPfannschmidt
RonnyPfannschmidt requested review from bluetech and nicoddemus and removed request for nicoddemus November 25, 2026 20:48

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pytest hangs when RecursionError happens for MagicMock

2 participants