Include underlying error when AST safety check parsing fails (#2693)
This commit is contained in:
parent
93701d249e
commit
3501cefb09
@ -5,6 +5,8 @@
|
|||||||
### _Black_
|
### _Black_
|
||||||
|
|
||||||
- Improve error message for invalid regular expression (#2678)
|
- Improve error message for invalid regular expression (#2678)
|
||||||
|
- Improve error message when parsing fails during AST safety check by embedding the
|
||||||
|
underlying SyntaxError (#2693)
|
||||||
- Fix mapping cases that contain as-expressions, like `case {"key": 1 | 2 as password}`
|
- Fix mapping cases that contain as-expressions, like `case {"key": 1 | 2 as password}`
|
||||||
(#2686)
|
(#2686)
|
||||||
- No longer color diff headers white as it's unreadable in light themed terminals
|
- No longer color diff headers white as it's unreadable in light themed terminals
|
||||||
|
@ -1305,7 +1305,7 @@ def assert_equivalent(src: str, dst: str, *, pass_num: int = 1) -> None:
|
|||||||
src_ast = parse_ast(src)
|
src_ast = parse_ast(src)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise AssertionError(
|
raise AssertionError(
|
||||||
"cannot use --safe with this file; failed to parse source file."
|
f"cannot use --safe with this file; failed to parse source file: {exc}"
|
||||||
) from exc
|
) from exc
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -1584,6 +1584,16 @@ def test_for_handled_unexpected_eof_error(self) -> None:
|
|||||||
|
|
||||||
exc_info.match("Cannot parse: 2:0: EOF in multi-line statement")
|
exc_info.match("Cannot parse: 2:0: EOF in multi-line statement")
|
||||||
|
|
||||||
|
def test_equivalency_ast_parse_failure_includes_error(self) -> None:
|
||||||
|
with pytest.raises(AssertionError) as err:
|
||||||
|
black.assert_equivalent("a«»a = 1", "a«»a = 1")
|
||||||
|
|
||||||
|
err.match("--safe")
|
||||||
|
# Unfortunately the SyntaxError message has changed in newer versions so we
|
||||||
|
# can't match it directly.
|
||||||
|
err.match("invalid character")
|
||||||
|
err.match(r"\(<unknown>, line 1\)")
|
||||||
|
|
||||||
|
|
||||||
class TestCaching:
|
class TestCaching:
|
||||||
def test_cache_broken_file(self) -> None:
|
def test_cache_broken_file(self) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user