Skip to content

gh-98278: Highlight both mismatched brackets in SyntaxError - #162071

Open
Badi-Rodriguez wants to merge 1 commit into
python:mainfrom
Badi-Rodriguez:gh-98278-bracket-carets
Open

Badi-Rodriguez wants to merge 1 commit into
python:mainfrom
Badi-Rodriguez:gh-98278-bracket-carets

Conversation

@Badi-Rodriguez

Copy link
Copy Markdown

Summary

Improve the display of SyntaxError for mismatched brackets on the same source line by highlighting both the unmatched opening delimiter and the mismatched closing delimiter, as requested in gh-98278.

  • Pass the opening delimiter's character column from the tokenizer through a private _opening_offset attribute on the raised SyntaxError.
  • Render two carets in traceback output, including colorized output and source lines containing Unicode characters of different display widths.
  • Preserve the original exception message and closing delimiter's primary SyntaxError.offset.
  • Keep existing single-caret behavior for mismatched brackets spanning multiple lines.
  • Add regression tests and a NEWS entry.

Tests

Local validation completed prior to opening this PR:

  • CPython tests: 1,010 passed, 5 skipped.
  • patchcheck passed.
  • git diff --check passed.

Issue: gh-98278.

@python-cla-bot

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

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

Labels

awaiting review type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant