GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-122478: Remove internal frames from tracebacks in REPL by serhiy-storchaka · Pull Request #122528 · python/cpython Conversation
| |||||||||||||||||||||||||||||||||||||||
|
This has a very slight side-effect of not showing error position for a call that raises in >>> c = codeop.compile_command(1) Traceback (most recent call last): File "<python-input-11>", line 1, in <module> c = codeop.compile_command(1) File "~\PycharmProjects\cpython\Lib\codeop.py", line 102, in compile_command return _maybe_compile(_compile, source, filename, symbol) File "~\PycharmProjects\cpython\Lib\codeop.py", line 51, in _maybe_compile for line in source.split("\n"): ^^^^^^^^^^^^ AttributeError: 'int' object has no attribute 'split' Versus: >>> codeop.compile_command(1) Traceback (most recent call last): File "<python-input-1>", line 1, in <module> codeop.compile_command(1) ~~~~~~~~~~~~~~~~~~~~~~^^^ File "~\PycharmProjects\cpython\Lib\codeop.py", line 102, in compile_command return _maybe_compile(_compile, source, filename, symbol) File "~\PycharmProjects\cpython\Lib\codeop.py", line 51, in _maybe_compile for line in source.split("\n"): ^^^^^^^^^^^^ AttributeError: 'int' object has no attribute 'split' |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@cfbolz do you mind to make a review of this PR? @iritkatriel, you already did similar work with cleaning up tracebacks. Are you interesting in this issue? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@devdanzin, the difference is because in one example the code is |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Nope, user error on my part. Sorry about the noise. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| self._call_excepthook(ei[0], ei[1], last_tb) | ||
| typ, value, tb = sys.exc_info() | ||
| # Remove internal frames (in modules code and codeop) from traceback. | ||
| while tb and tb.tb_frame.f_globals.get('__name__') in ('code', 'codeop'): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
unittest's _clean_tracebacks() also looks at the chained exceptions.
Maybe it makes sense to implement this in the traceback module, and reuse?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actually, even this loop is an overpower on one side and not enough on other side. I initially added it to handle both compile-time (this is why copeop) and run-time errors. But then I have found that compile-time errors should not have a traceback at all.
Now I see that we should just remove one level from a traceback -- the one that refers to the code calls exec(). This is also necessary for IDLE which overrides runcode() -- in this case the top frame is in the idlelib.pyshell module.
This will not work if the code calls exec() not directly but via wrapper. Ideally we should find the frame that calls exec() (or eval()) and drop it and above frames, but there is no easy way to do this. It would help if exec() and eval() add a special marker in the traceback, but this would be a new feature.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -0,0 +1,3 @@ | |||
| Remove internal frames from tracebacks shown in | |||
| :class:`code.InteractiveInterpreter` with non-default :func:`sys.excepthook`. | |||
| Save correct tracebacks in :attr:`sys.last_traceback` and update ``__traceback__`` attribute of :attr:`sys.last_value` and :attr:`sys.last_exc`. | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by 'the correct' traceback?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
With removed frames.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@serhiy-storchaka I think the PR is good, I like the fact that the (This is probably unrelated to your PR, but |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
pythonGH-122528) Frames of methods in code and codeop modules was show with non-default sys.excepthook. Save correct tracebacks in sys.last_traceback and update __traceback__ attribute of sys.last_value and sys.last_exc. (cherry picked from commit e73e7a7) Co-authored-by: Serhiy Storchaka <[email protected]>
|
GH-122816 is a backport of this pull request to the 3.12 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…onGH-122528) Frames of methods in code and codeop modules was show with non-default sys.excepthook. Save correct tracebacks in sys.last_traceback and update __traceback__ attribute of sys.last_value and sys.last_exc. (cherry picked from commit e73e7a7) Co-authored-by: Serhiy Storchaka <[email protected]>
|
GH-122817 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…onGH-122528) Frames of methods in code and codeop modules was show with non-default sys.excepthook. Save correct tracebacks in sys.last_traceback and update __traceback__ attribute of sys.last_value and sys.last_exc.
pythonGH-122528) Frames of methods in code and codeop modules was show with non-default sys.excepthook. Save correct tracebacks in sys.last_traceback and update __traceback__ attribute of sys.last_value and sys.last_exc. (cherry picked from commit e73e7a7) Co-authored-by: Serhiy Storchaka <[email protected]>
|
GH-123227 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
pythonGH-122528) Frames of methods in code and codeop modules was show with non-default sys.excepthook. Save correct tracebacks in sys.last_traceback and update __traceback__ attribute of sys.last_value and sys.last_exc. (cherry picked from commit e73e7a7) Co-authored-by: Serhiy Storchaka <[email protected]>
…122528) (#123227) Frames of methods in code and codeop modules was show with non-default sys.excepthook. Save correct tracebacks in sys.last_traceback and update __traceback__ attribute of sys.last_value and sys.last_exc. (cherry picked from commit e73e7a7) Co-authored-by: Serhiy Storchaka <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.