-
Notifications
You must be signed in to change notification settings - Fork 59
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
Enhancement: Extended Snapshot - Capturing Variables in '__main__' Stack Frame #1004
Conversation
Pull Request Test Coverage Report for Build 7859135880
💛 - Coveralls |
python_ta/debug/snapshot.py
Outdated
@@ -15,6 +34,9 @@ def snapshot(): | |||
frame = inspect.currentframe().f_back | |||
|
|||
while frame: | |||
if len(local_vars) == 0: # to ensure we do not add main stack frame multiple times |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still isn't what I'm looking for. Look at the condition on line 40 and ask why it's there, and how you can use it to address the current problem.
Hi @david-yz-liu! I believe the necessity of the if condition was to only pinpoint local variables, and do not investigate global context. That's why I called the helper function after that check (and with the same indentation level with the if condition) so that the variables within the global context will be added to the accumulator, after the check is made. |
Motivation and Context
The current
snapshot
function gathers variables only from function calls, potentially nested. To enhance its utility, we aim to expand its capabilities, and our goal is to include variables in the top-level scope, specifically those defined in the main block. This expansion caters to a beginner-friendly Python context, providing a more comprehensive snapshot functionality.Your Changes
Description:
I've updated the snapshot.py module to improve the snapshot function. Now, it captures specific global variables, particularly those defined at the top level within the module where the snapshot function is called. The unit tests have been adjusted accordingly to validate and cover these improvements thoroughly.
Type of change (select all that apply):
Testing
I've modified the unit tests for the snapshot function and tested the new feature across different levels of nesting. This ensures that the tests now align with the recent changes and thoroughly validate the functionality under various scenarios.
Questions and Comments (if applicable)
N/A
Checklist