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
UnboundLocalError when trying to raise exceptions inside execfile #46631
Comments
Found a bug when trying to integrate figleaf coverage into trunk. I import os
import sys
def foo(f, e, o):
pass
sys.settrace(foo)
import __main__
execfile('test_broken.py', __main__.__dict__) The second file is the test (test_broken.py): # This code breaks on trunk def test_foo():
class CustomException(Exception):
pass
class SomeClass:
def foo(self):
raise CustomException
# The error only appears with enough nested blocks.
if (True == True):
try:
raise IOError
except CustomException:
pass It should raise IOError. When run, it gives the following output: jerry-seutters-computer:~/code/python/core_wierd_bug_minimal jseutter$
../core/python.exe figleaf
Traceback (most recent call last):
File "figleaf", line 10, in <module>
execfile('test_broken.py', __main__.__dict__)
File "test_broken.py", line 18, in <module>
test_foo()
File "test_broken.py", line 15, in test_foo
except CustomException:
UnboundLocalError: local variable 'CustomException' referenced before
assignment
[10019 refs] |
Just note the error happens even without the try/except block inside the |
I can't reproduce this with r63075... |
I get it with r63075, r63085, on Linux. |
Apologies, I didn't run the test case correctly; I do get the error as |
Shorter trigger code.. |
Some debugging helper code and my conclutions of one work day: What I found:
1. The CustomException is disappearing from locals()
2. PyFrame_FastToLocals() (from that .c file) is updating the locals,
and removing that exception from there.
3. In the failing case this code:
if (deref) {
assert(PyCell_Check(value));
value = PyCell_GET(value);
}
is returning value==NULL. Don't know why that happens. |
The problem seems to have been introduced by r53954. |
The problem is in PyFrame_LocalsToFast. (As I understand it: "Locals" refers to the locals() dictionary of the When defining a class, PyFrame_FastToLocals does not copy the free I attach a patch that makes PyFrame_LocalsToFast symmetric to |
Committed as r65177. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: