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.
This commit is contained in:
parent
c198a7a67e
commit
c90fdc684b
|
@ -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)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue