enhance: enhancement of the syntex error reporting#4992
enhance: enhancement of the syntex error reporting#4992MohamedSharfan wants to merge 11 commits intopsf:mainfrom
Conversation
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Pull request overview
This PR attempts to enhance Black's syntax error reporting by displaying line numbers, column positions, and using a caret (^) to point to the exact location of syntax errors. The goal is to improve user experience when Black encounters invalid Python syntax, making it easier for developers to identify and fix syntax errors.
Changes:
- Added exception handling for InvalidInput in the
_format_str_oncefunction - Implemented line/column extraction from error messages
- Added error display with caret positioning to indicate error location
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
The message should be changed here, inside lib2to3_parse: Line 84 in e015af4 Also, Copilot's suggestions are correct; please review them. |
ok sure i will review them and commit again |
| f"Cannot parse{tv_str}: {lineno}:{column}: {faulty_line}" | ||
| caret_line = "^".rjust(column) | ||
| message = ( | ||
| f"SyntaxError is in line {lineno}, column {column}:\n" |
There was a problem hiding this comment.
Please use wording similar to how it was previously, this message is confusing (and spelled wrong)!
Please also review the test failures.
Description
My fix improves Black's syntex error reporting when parsing fails.
I have made a test file to see the error messege that reports

currently when Black encounters invalid python syntex, it reports something like this

The changes i have changes to enhance the error message reporting
fixes #4820
Checklist - did you ...
--previewstyle, following the stability policy?CHANGES.mdif necessary?