bpo-45711: Change exc_info related APIs to derive type and traceback from the exception instance#29780
Conversation
18b2949 to
6a766ce
Compare
November 25, 2021 17:58
…from the exception instance
6a766ce to
e8645ff
Compare
November 25, 2021 17:59
gvanrossum
left a comment
There was a problem hiding this comment.
Nice and straightforward. I have a few nits but really, this could go as-is.
Sorry, something went wrong.
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
|
There is one more place where the move to using traceback from the exception can be visible from a program - in the eval loop when we reraise. See iritkatriel#32 . I think maybe we should add that change to this PR. |
Sorry, something went wrong.
It comes down to how certain we are that that's not going to break anything. I don't see an assertion in there that checks that |
Sorry, something went wrong.
It will break the same edge case as the other changes in this pr - when you change the traceback on the handled exception in an except clause and then do ‘raise’. |
Sorry, something went wrong.
Okay, that's fine then. I was worried that it might in some cases insert or leave out a frame, but it sounds like that would only happen if you mess around with the exception (e.g. raising and catching it, like you showed earlier). That edge case is acceptable to me as long as we announce it clearly in what's new. (I am still concerned about something else -- sometimes "raise e" and "raise" don't do the same thing even if "e" is the exception being handled. But that is not affected by these changes -- that difference will persist, and arguably it is correct (though it surprises me occasionally). Even if we wanted to change it, we couldn't, because it is not an obscure corner case -- the semantics are clearly described. Please ignore my mumbling here.) |
Sorry, something went wrong.
|
FTR - an example of what will change for raise: Old: New: |
Sorry, something went wrong.
A related story: After we moved our system from python 2 to python 3 we got bug reports about nonsensical tracebacks. Turned out we had something like this: The two tracebacks were the same in python 2, but in python 3 you get: The fix was to change the raise to |
Sorry, something went wrong.
Hm, this makes me realize that there may be a bug in asyncio. When you call a Future's result() method, if the Future represents an error, it raises self.exception. But that means that each time you attempt to get the result, you'll get an extra line (or more) added to the traceback. This seems quite unintended -- the author of the code (me) apparently wasn't aware of this behavior. Curiously, nobody's ever complained about nonsensical tracebacks. To fix it, we'd have to add a separate attribute to hold the traceback. Oh, and the same bug exists in concurrent.futures. (Which I did not write.) In fact now I suspect it exists all over the stdlib where exceptions are stored and raised later. |
Sorry, something went wrong.
What made our tracebacks obviously nonsensical is that we raise the same exception from two different places. There is no way to get I've created bpo-45924 to track this. |
Sorry, something went wrong.
|
🤖 New build scheduled with the buildbot fleet by @iritkatriel for commit 05af230 🤖 If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again. |
Sorry, something went wrong.
gvanrossum
left a comment
There was a problem hiding this comment.
LGTM. Land any time!
Sorry, something went wrong.
* main: (21 commits) bpo-45876: Have stdev() also use decimal specific square root. (pythonGH-29869) bpo-45876: Correctly rounded stdev() and pstdev() for the Decimal case (pythonGH-29828) bpo-45711: Change exc_info related APIs to derive type and traceback from the exception instance (pythonGH-29780) bpo-30533:Add function inspect.getmembers_static that does not call properties or dynamic properties. (python#20911) bpo-45476: Disallow using asdl_seq_GET() as l-value (pythonGH-29866) bpo-45476: Add _Py_RVALUE() macro (pythonGH-29860) bpo-33381: [doc] strftime's %f option may pad zeros on the left or the right (pythonGH-29801) Fix EncodingWarning in Tools/freeze/test/freeze.py (pythonGH-29742) no-issue: remove unused import from test_graphlib.py (pythonGH-29853) bpo-45931: Prevent Directory.Build.props/targets from leaking from directories above the repo when building on Windows (pythonGH-29854) bpo-45653: fix test_embed on windows (pythonGH-29814) bpo-45917: Add math.exp2() method - return 2 raised to the power of x (pythonGH-29829) bpo-43905: Expand dataclasses.astuple() and asdict() docs (pythonGH-26154) bpo-44391: Remove unused argument from a varargs call. (pythonGH-29843) bpo-45881: configure --with-freeze-module --with-build-python (pythonGH-29835) bpo-45847: PY_STDLIB_MOD_SIMPLE now checks py_stdlib_not_available (pythonGH-29844) bpo-45828: Use unraisable exceptions within sqlite3 callbacks (FH-29591) bpo-40280: Emscripten systems use .wasm suffix by default (pythonGH-29842) bpo-45723: Sort the grand AC_CHECK_HEADERS check (pythonGH-29846) bpo-45847: Make socket module conditional (pythonGH-29769) ...
* main: (21 commits) bpo-45876: Have stdev() also use decimal specific square root. (pythonGH-29869) bpo-45876: Correctly rounded stdev() and pstdev() for the Decimal case (pythonGH-29828) bpo-45711: Change exc_info related APIs to derive type and traceback from the exception instance (pythonGH-29780) bpo-30533:Add function inspect.getmembers_static that does not call properties or dynamic properties. (python#20911) bpo-45476: Disallow using asdl_seq_GET() as l-value (pythonGH-29866) bpo-45476: Add _Py_RVALUE() macro (pythonGH-29860) bpo-33381: [doc] strftime's %f option may pad zeros on the left or the right (pythonGH-29801) Fix EncodingWarning in Tools/freeze/test/freeze.py (pythonGH-29742) no-issue: remove unused import from test_graphlib.py (pythonGH-29853) bpo-45931: Prevent Directory.Build.props/targets from leaking from directories above the repo when building on Windows (pythonGH-29854) bpo-45653: fix test_embed on windows (pythonGH-29814) bpo-45917: Add math.exp2() method - return 2 raised to the power of x (pythonGH-29829) bpo-43905: Expand dataclasses.astuple() and asdict() docs (pythonGH-26154) bpo-44391: Remove unused argument from a varargs call. (pythonGH-29843) bpo-45881: configure --with-freeze-module --with-build-python (pythonGH-29835) bpo-45847: PY_STDLIB_MOD_SIMPLE now checks py_stdlib_not_available (pythonGH-29844) bpo-45828: Use unraisable exceptions within sqlite3 callbacks (FH-29591) bpo-40280: Emscripten systems use .wasm suffix by default (pythonGH-29842) bpo-45723: Sort the grand AC_CHECK_HEADERS check (pythonGH-29846) bpo-45847: Make socket module conditional (pythonGH-29769) ...
https://bugs.python.org/issue45711