Perfect your code
With built-in code review tools, GitHub makes it easy to raise the quality bar before you ship. Join the 40 million developers who've merged over 200 million pull requests.
Sign up for free See pricing for teams and enterprisesbpo-39114: Fix tracing of except handlers with name binding #17769
Conversation
This comment has been minimized.
This comment has been minimized.
@nedbat Can you confirm if this fixes your issue? |
This comment has been minimized.
This comment has been minimized.
@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 |
This comment has been minimized.
This comment has been minimized.
@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? |
This comment has been minimized.
This comment has been minimized.
@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. |
This comment has been minimized.
This comment has been minimized.
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
This comment has been minimized.
This comment has been minimized.
@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. |
This comment has been minimized.
This comment has been minimized.
@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:
|
This comment has been minimized.
This comment has been minimized.
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 |
This comment has been minimized.
This comment has been minimized.
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? |
This comment has been minimized.
This comment has been minimized.
@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. |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
@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 comment has been minimized.
This comment has been minimized.
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. |
04ec7a1
into
python:master
bpo-39114: Fix tracing of except handlers with name binding (pythonGH-17769)
pablogsal commentedDec 31, 2019
•
edited by bedevere-bot
https://bugs.python.org/issue39114