-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Is your feature request related to a problem? Please describe.
When black encounters a Python file with a syntax error, the current error message is often dense, confusing. This forces the developer to spend extra time deciphering what went wrong and where.
Describe the solution you'd like
I propose enhancing the error reporting for SyntaxErrors to be more user-friendly, clear, and actionable.
Instead of the current one-line error, black could print a more detailed, multi-line message that pinpoints the error, much like Python's own interpreter.
Proposed new error output:
$ black test.py
Error: Cannot parse test.py
black's parser found a syntax error on or near line 4.
This is often caused by a missing ':' on the line before.
File "test.py", line 3:
def my_func()
^
SyntaxError: expected ':'
Please fix the syntax error before formatting.
Describe alternatives you've considered
Another alternative is to use a separate linter, but it would be a significant user experience improvement if black could provide this simple feedback on its own.
This proposal is not about adding new formatting rules or configuration. It's about improving the core user experience and developer productivity. By providing clear, actionable error messages, black becomes an even more helpful tool.
This could likely be implemented by catching the SyntaxError (or parser-specific error) and extracting the line number, column, and text to format it into a friendlier "pretty print" error message before exiting.