-
Notifications
You must be signed in to change notification settings - Fork 955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Support depth=float('inf')
#200
Comments
Claim, I will try to add this feature |
Great. It's likely easy. |
Hi!I wanted to discuss a few ideas with you to ensure that my changes align with the project's goals. I've identified a line in trace.py (line 406) that might need modification. Specifically, there's a for loop that iterates from 0 to depth. I propose introducing an if statement to create two branches: If self.depth == inf, the loop would be modified to continue up the call stack until there are no more frames to trace. Thank you for your time, and I look forward to your feedback. |
Kind of, yes, but do it like this:
Write tests for it without my guidance and show me. |
ok. Thank you! |
I also observed an issue. After implementing this feature, the program can trace an infinite depth, which results in the display of system functions, such as:
This scenario can also occur in the original code when setting the depth to a significantly large value. For instance, consider the following test case:
I am uncertain whether we should halt tracing when such situations arise. |
That is a potential problem, but it's unrelated to this change. So go forward with this change, and after it's merged, if you'll be interested you can investigate this problem. One good first step in investigating this problem is see whether it happens with https://github.com/alexmojaki/snoop . Also, when you copy-paste code to GitHub, make sure you're using a multiline code block rather than single line, and make sure it's properly formatted. (Both code samples in your last message don't show properly.) |
Thank you! Indeed, it appears that the issue isn't directly tied to this particular change. I've had the opportunity to review the project you provided, and it doesn't exhibit the same problem. While the modification to float('inf') isn't the root cause of the issue, it did create complications when I was writing tests. To address this, I attempted to resolve the aforementioned problem. The issue seems to stem from the code not verifying if the current frame is an internal frame. To tackle this, I introduced a condition that checks if the frame candidate is an internal frame; if so, it returns None, indicating that it will not be traced. if not (frame.f_code in self.target_codes or frame in self.target_frames):
if self.depth == 1:
# We did the most common and quickest check above, because the
# trace function runs so incredibly often, therefore it's
# crucial to hyper-optimize it for the common case.
return None
elif self._is_internal_frame(frame):
return None
else:
_frame_candidate = frame
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:
return None |
No description provided.
The text was updated successfully, but these errors were encountered: