]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Include underlying error when AST safety check parsing fails (#2693)
authorRichard Si <63936253+ichard26@users.noreply.github.com>
Wed, 15 Dec 2021 02:21:28 +0000 (21:21 -0500)
committerGitHub <noreply@github.com>
Wed, 15 Dec 2021 02:21:28 +0000 (18:21 -0800)
CHANGES.md
src/black/__init__.py
tests/test_black.py

index c73295c4a0dad077a8fb0503135eb5ca6c063099..9208be7cd968e2997e9478ff71a24ef99bcf5e0a 100644 (file)
@@ -5,6 +5,8 @@
 ### _Black_
 
 - 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}`
   (#2686)
 - No longer color diff headers white as it's unreadable in light themed terminals
index 59018d00de469c5e276a98f84cca506e44c29d80..f2efdec83b22a53d1ad00f6d1b1057dcae1f0c0f 100644 (file)
@@ -1305,7 +1305,7 @@ def assert_equivalent(src: str, dst: str, *, pass_num: int = 1) -> None:
         src_ast = parse_ast(src)
     except Exception as exc:
         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
 
     try:
index 468f00fcafb82c43a2cca3677cec918f3518b5f3..63cd716c0bb80aeea9cf31c274ead6b1b930d4e6 100644 (file)
@@ -1584,6 +1584,16 @@ class BlackTestCase(BlackBaseTestCase):
 
         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:
     def test_cache_broken_file(self) -> None: