-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-39114: Fix tracing of except handlers with name binding #17769
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
Conversation
@nedbat Can you confirm if this fixes your issue? |
@markshannon Can you check if this looks right to you? I am not completely sure what was originally this guarding against (not sure what the comment |
@pablogsal Thanks, I'll take a look at it. Right now, this change is failing other tests of mine. We should talk about how to add more regression tests to the Python test suite so that we don't have to have these kinds of bug reports in the first place. As an example, shouldn't this pull request add some tests to confirm the fix? |
@pablogsal good news: looks like the coverage.py tests that fail with this change are testing the same things that the current test failure here is testing. |
Yes, but for now I am not sure that the fix is even correct so I still didn't make tests for it :) |
70be868
to
bb3a186
Compare
@nedbat Can you check your test suite with this version of the PR? If Mark confirms that this looks good to him, I can add some tests. |
@pablogsal Thanks. This PR fixes the two problems reported in bpo-39114. But it seems to lose the tracing for some finally clauses. /tmp/pr17769.py:
In Python 3.8 and 3.9a2, line 16 (the finally clause) is reported. With this PR, it is not:
|
Thanks, @nedbat. Is very unfortunate that we don't have enough coverage for the trace functionality to detect this when iterating over changes in the compiler.... I will try to find a solution for this in the meantime but @markshannon is more familiar with the changes in this code and probably knows what we are missing. Certainly we need to improve the test suite of |
I have updated the PR with a new test covering the last case you reported. @nedbat Is there any way I can try your test suite to make sure I am not missing something? |
@pablogsal The tests all pass with this change, thanks! We can work on how to run the coverage.py test suite locally. In this case, I had already xfail'ed these tests on 3.9, so it was a little involved to see them run again. |
Thanks @pablogsal. The root problem is that we have no way to express that some sequence of instructions does not correspond to any actual source. |
@markshannon I'm not sure what you mean by "sequence of instructions does not correspond to any actual source." What's the example of that here? |
This is because: try:
...
except Exception as e:
... Really generates this code try:
...
except Exception as e:
try:
...
finally:
e = None
del e The reason is to avoid cycles in the gc with the exception name and keep alive entire stacks. The bytecode for the finally that gets generated have no real source lines and is what is generating the weird traces because the way unwinding and frame blocks work. This is just one example, there are more cases when we need to generate bytecode that does not correspond to "real" user code. |
bpo-39114: Fix tracing of except handlers with name binding (pythonGH-17769)
…-17769) When producing the bytecode of exception handlers with name binding (like `except Exception as e`) we need to produce a try-finally block to make sure that the name is deleted after the handler is executed to prevent cycles in the stack frame objects. The bytecode associated with this try-finally block does not have source lines associated and it was causing problems when the tracing functionality was running over it.
https://bugs.python.org/issue39114