Skip to content

Commit

Permalink
Hint at likely cause of ast parsing failure in error message (#2786)
Browse files Browse the repository at this point in the history
Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
  • Loading branch information
4 people committed Jan 20, 2022
1 parent 6e97c5f commit e66e0f8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/black/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,10 @@ def assert_equivalent(src: str, dst: str, *, pass_num: int = 1) -> None:
src_ast = parse_ast(src)
except Exception as exc:
raise AssertionError(
f"cannot use --safe with this file; failed to parse source file: {exc}"
f"cannot use --safe with this file; failed to parse source file AST: "
f"{exc}\n"
f"This could be caused by running Black with an older Python version "
f"that does not support new syntax used in your source file."
) from exc

try:
Expand Down

0 comments on commit e66e0f8

Please sign in to comment.