X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/136930fccb99320865622e12ffc21bdd45fd7501..f52cb0fe3775829245acfeae191e8d63120c8416:/src/black/parsing.py diff --git a/src/black/parsing.py b/src/black/parsing.py index e384056..b673027 100644 --- a/src/black/parsing.py +++ b/src/black/parsing.py @@ -17,6 +17,7 @@ from blib2to3 import pygram from blib2to3.pgen2 import driver from blib2to3.pgen2.grammar import Grammar from blib2to3.pgen2.parse import ParseError +from blib2to3.pgen2.tokenize import TokenError from black.mode import TargetVersion, Feature, supports_feature from black.nodes import syms @@ -109,6 +110,12 @@ def lib2to3_parse(src_txt: str, target_versions: Iterable[TargetVersion] = ()) - except IndexError: faulty_line = "" exc = InvalidInput(f"Cannot parse: {lineno}:{column}: {faulty_line}") + + except TokenError as te: + # In edge cases these are raised; and typically don't have a "faulty_line". + lineno, column = te.args[1] + exc = InvalidInput(f"Cannot parse: {lineno}:{column}: {te.args[0]}") + else: raise exc from None