Skip to content

Commit

Permalink
fastparse: improve error reporting for f-string syntax errors (#8970)
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja authored Jun 9, 2020
1 parent 793cf18 commit 068594e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ def parse(source: Union[str, bytes],
tree.path = fnam
tree.is_stub = is_stub_file
except SyntaxError as e:
if sys.version_info < (3, 9) and e.filename == "<fstring>":
# In Python 3.8 and earlier, syntax errors in f-strings have lineno relative to the
# start of the f-string. This would be misleading, as mypy will report the error as the
# lineno within the file.
e.lineno = None
errors.report(e.lineno if e.lineno is not None else -1, e.offset, e.msg, blocker=True,
code=codes.SYNTAX)
tree = MypyFile([], [], False, {})
Expand Down

0 comments on commit 068594e

Please sign in to comment.