Skip to content

Commit c90fdc6

Browse files
committed
code: remove unneeded comparison eval wrapper
Given a `RecursionError` traceback, the `Traceback.recursionindex()` method returns the index of the frame which started the recursion (repeated set of frames). To do so it attempts to check whether two frames are equivalent. Just checking the function/line is not enough because the recursion variable(s) might differ (e.g. imagine the numeric value in a recursive factorial implementation). So it also compares the `f_locals` (local variables) of each frame for equivalence. For some reason, the locals comparison is wrapped in an `eval` whose purpose is to evaluate the comparison in one of the compared frame's context (locals + globals in scope). However, I can not think of any way in which the global scope could affect the evaluation. It would have an affect when the locals are bound but that's already done. So this seems unnecessary - remove it.
1 parent c198a7a commit c90fdc6

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

src/_pytest/_code/code.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -422,21 +422,12 @@ def recursionindex(self) -> Optional[int]:
422422
f = entry.frame
423423
loc = f.f_locals
424424
for otherloc in values:
425-
if f.eval(
426-
co_equal,
427-
__recursioncache_locals_1=loc,
428-
__recursioncache_locals_2=otherloc,
429-
):
425+
if otherloc == loc:
430426
return i
431427
values.append(entry.frame.f_locals)
432428
return None
433429

434430

435-
co_equal = compile(
436-
"__recursioncache_locals_1 == __recursioncache_locals_2", "?", "eval"
437-
)
438-
439-
440431
E = TypeVar("E", bound=BaseException, covariant=True)
441432

442433

0 commit comments

Comments
 (0)