gh-148306: Fix dis.distb() crash when traceback is None#148317
gh-148306: Fix dis.distb() crash when traceback is None#148317Ignyra wants to merge 1 commit intopython:mainfrom
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
a6f5978 to
fe1e2f3
Compare
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
fe1e2f3 to
fe4fb9a
Compare
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
fe4fb9a to
25c82e9
Compare
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
| tb = sys.last_exc.__traceback__ | ||
| exc = sys.last_exc | ||
| tb = exc.__traceback__ | ||
| if isinstance(exc, SyntaxError): |
There was a problem hiding this comment.
Filtering out all SyntaxErrors here doesn’t seem quite right. It should still work if a SyntaxError is raised elsewhere. I think you could check whether tb is None, or just move the while loop below into the try block.
There was a problem hiding this comment.
I may be mistaken but from my understanding, a SyntaxError can not produce a traceback, since it occurs before any bytecode is executed, so my intention was to make the resulting error more informative in that specific case, to distinguish it from the other error that is raised where no exception has occurred at all.
That said, I can switch to the alternative approach if you think that would be more appropriate.
Summary
Prevent
dis.distb()from failing withAttributeErrorwhen the last exception is aSyntaxError.Bug
A
SyntaxErroris raised while parsing or compiling source, before any Python bytecode is executed, so there is no traceback available fordis.distb()to disassemble.distb()currently assumes a traceback is present and unconditionally accesses tb.tb_next.Fix
If the last exception is a
SyntaxError, raiseRuntimeError("cannot disassemble a SyntaxError")instead of failing with anAttributeError.Also add a regression test simulating REPL state for a
SyntaxError.This is my first contribution to CPython. I’d really appreciate any feedback. Thanks!
dis.distb()raise AttributeError when the previous input fails to compile #148306