-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
Description
Summary
While going through the remaining errors we don't detect in #7633, I noticed a surprising unexpected EOF while parsing error caused by a case like this:
class C:
def f():
return 1, \I can't reproduce this in the playground, but this is the output locally with this saved as try.py:
$ python -m ast try.py
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/usr/lib/python3.13/ast.py", line 1871, in <module>
main()
~~~~^^
File "/usr/lib/python3.13/ast.py", line 1867, in main
tree = parse(source, name, args.mode, type_comments=args.no_type_comments)
File "/usr/lib/python3.13/ast.py", line 54, in parse
return compile(source, filename, mode, flags,
_feature_version=feature_version, optimize=optimize)
File "try.py", line 3
return 1, \
^
SyntaxError: unexpected EOF while parsing
$ ruff check try.py
All checks passed!And I see the same thing for a single \ as input:
$ python -m ast <<<'\'
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/usr/lib/python3.13/ast.py", line 1871, in <module>
main()
~~~~^^
File "/usr/lib/python3.13/ast.py", line 1867, in main
tree = parse(source, name, args.mode, type_comments=args.no_type_comments)
File "/usr/lib/python3.13/ast.py", line 54, in parse
return compile(source, filename, mode, flags,
_feature_version=feature_version, optimize=optimize)
File "<stdin>", line 1
\
^
SyntaxError: unexpected EOF while parsing
$ ruff check - <<<'\'
All checks passed!I'm not sure what's different in the playground, but it detects both of these cases, and it reports a single Unknown token in the case of the single \.
Version
ruff 0.11.5 (7186d5e 2025-04-10)
Reactions are currently unavailable