Skip to content

Commit 068594e

Browse files
authored
fastparse: improve error reporting for f-string syntax errors (python#8970)
1 parent 793cf18 commit 068594e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

mypy/fastparse.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ def parse(source: Union[str, bytes],
169169
tree.path = fnam
170170
tree.is_stub = is_stub_file
171171
except SyntaxError as e:
172+
if sys.version_info < (3, 9) and e.filename == "<fstring>":
173+
# In Python 3.8 and earlier, syntax errors in f-strings have lineno relative to the
174+
# start of the f-string. This would be misleading, as mypy will report the error as the
175+
# lineno within the file.
176+
e.lineno = None
172177
errors.report(e.lineno if e.lineno is not None else -1, e.offset, e.msg, blocker=True,
173178
code=codes.SYNTAX)
174179
tree = MypyFile([], [], False, {})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy