From c90fdc684b083a185523d487d51b35971978e270 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sun, 23 May 2021 20:47:56 +0300 Subject: [PATCH] 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. --- src/_pytest/_code/code.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py index 992a4d735..d9a6b9edb 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -422,21 +422,12 @@ class Traceback(List[TracebackEntry]): f = entry.frame loc = f.f_locals for otherloc in values: - if f.eval( - co_equal, - __recursioncache_locals_1=loc, - __recursioncache_locals_2=otherloc, - ): + if otherloc == loc: return i values.append(entry.frame.f_locals) return None -co_equal = compile( - "__recursioncache_locals_1 == __recursioncache_locals_2", "?", "eval" -) - - E = TypeVar("E", bound=BaseException, covariant=True)