Modify depth to depth_iterator to support float('inf') and also break if _frame_candidate is internal_frame

This commit is contained in:
Elijah Qi 2023-04-15 22:11:25 -04:00
parent caf4ec584a
commit b9f35dbcb2

View file

@ -403,10 +403,13 @@ class Tracer:
return None
else:
_frame_candidate = frame
for i in range(1, self.depth):
depth_iterator = itertools.count(1) if (self.depth == float('inf')) else range(1, self.depth)
for i in depth_iterator:
_frame_candidate = _frame_candidate.f_back
if _frame_candidate is None:
return None
elif self._is_internal_frame(_frame_candidate):
return None
elif _frame_candidate.f_code in self.target_codes or _frame_candidate in self.target_frames:
break
else: