Skip to content

gh-148306: Fix dis.distb() crash when traceback is None#148317

Open
Ignyra wants to merge 1 commit intopython:mainfrom
Ignyra:fix-distb-syntaxerror
Open

gh-148306: Fix dis.distb() crash when traceback is None#148317
Ignyra wants to merge 1 commit intopython:mainfrom
Ignyra:fix-distb-syntaxerror

Conversation

@Ignyra
Copy link
Copy Markdown

@Ignyra Ignyra commented Apr 9, 2026

Summary

Prevent dis.distb() from failing with AttributeError when the last exception is a SyntaxError.

Bug

A SyntaxError is raised while parsing or compiling source, before any Python bytecode is executed, so there is no traceback available for dis.distb() to disassemble. distb() currently assumes a traceback is present and unconditionally accesses tb.tb_next.

Fix

If the last exception is a SyntaxError, raise RuntimeError("cannot disassemble a SyntaxError") instead of failing with an AttributeError.

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!

@python-cla-bot
Copy link
Copy Markdown

python-cla-bot bot commented Apr 9, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Apr 9, 2026

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 skip news label instead.

@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Apr 9, 2026

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 skip news label instead.

@Ignyra Ignyra force-pushed the fix-distb-syntaxerror branch from fe1e2f3 to fe4fb9a Compare April 9, 2026 23:22
@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Apr 9, 2026

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 skip news label instead.

@Ignyra Ignyra force-pushed the fix-distb-syntaxerror branch from fe4fb9a to 25c82e9 Compare April 9, 2026 23:32
@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Apr 9, 2026

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 skip news label instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant