-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
GH-94438: Fix RuntimeWarning
for jump tests in test_sys_settrace
#111341
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
GH-94438: Fix RuntimeWarning
for jump tests in test_sys_settrace
#111341
Conversation
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.
My intention was to have both of these jump after x was defined. I wonder if we should just update to both jump on line 2 and then have a separate test case for warnings?
We can do that, but the test case with warning tests what you want as well. Your test case does not rely on the variable x - it just needs some specific bytecode in the function (if I understand your test case correctly). Jumping from line 1 will just cover all the stuff you want to test, and it gives a little bit extra coverage for jumping before a variable is initialized. You wrote the test so I will definitely change it to jumping from line 2 if you want - just share my thoughts on this. |
That makes sense - thanks for catching this. Good learning for me too! |
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.
Looks good, thanks! This should be backported, yeah?
Yes as the original test was backported. |
RuntimeWarning
for jump tests in test_sys_settrace
Thanks @gaogaotiantian for the PR, and @brandtbucher for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
pythonGH-111341) (cherry picked from commit a254120) Co-authored-by: Tian Gao <[email protected]>
GH-111369 is a backport of this pull request to the 3.12 branch. |
Just to mention that the original test was backported to 3.11 as well. |
If I recall correctly, we only introduced these warnings in 3.12 (I think it coincided with the |
Yeah just checked the blame, the warning was added in 3.12. |
A couple of new tests were introduced to test_sys_settrace in #111237, however, two of them triggered a RuntimeWarning:
This is because the jump happens before all the local variables are assigned:
The test jumps on line 1 - before
x
is assigned toNone
. So whenframe.f_lineno
is being set, a warning is generated to alert the users that the unbound local variables are being set toNone
.This does not affect the validity or the result of the test, but I don't think it's intended, and it is not the best practice. Especially considering that the decorator can already take care of such warnings.
In this PR, two different fixes were applied to the problematic tests to maximize the diversity:
x
is assigned.A warning checker is also introduced so this won't happen in the future - if a test is not expecting a warning, then a warning is treated as an error. This might not be the best practice for all tests globally, but in this specific case, we do have "expected warnings" and it should count.