-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix EOF SyntaxError diagnostics #8429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e7e4d1d
922754d
485f808
4ba2f57
ba85fd7
7ad1675
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -752,7 +752,7 @@ impl VirtualMachine { | |
| Some(line + "\n") | ||
| } | ||
|
|
||
| let statement = source.and_then(|src| get_statement(src, error.location())); | ||
| let mut statement = source.and_then(|src| get_statement(src, error.location())); | ||
|
|
||
| let mut msg = error.to_string(); | ||
| if !msg.starts_with("Exceeds the limit ") | ||
|
|
@@ -799,6 +799,16 @@ impl VirtualMachine { | |
| } | ||
|
|
||
| let SyntaxErrorInfo { msg, narrow_caret } = syntax_error_info; | ||
| let unterminated_triple_quoted_string = | ||
| msg.starts_with("unterminated triple-quoted string literal"); | ||
| let unexpected_eof_error = msg == "unexpected EOF while parsing"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ShaharNaveh is this currently the best way to detect specific kind of error?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. atm, yes:( Either ruff don't expose the exact reason, or we need to do a major refactor of how we propagate the errors from the compiler
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how could it be detected after the major refactor? we can't do this message matching forever 😂
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ig you're right... maybe we can't escape it and just have our own ruff fork/have a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am sorry if the last comment was confusing. I'd like to ask what kind of refactor do you have in mind?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Looking at it again, I don't believe there's a refactor that would save us from doing a I've got a response for this issue in the past astral-sh/ruff#23334 (comment) (although I haven't asked to provide something like |
||
| if unterminated_triple_quoted_string | ||
| && let Some(statement) = statement.as_mut() | ||
| && statement.ends_with('\n') | ||
| { | ||
| // CPython omits the parser-added final newline from SyntaxError.text. | ||
| statement.pop(); | ||
| } | ||
| let check_version_suite_error = msg.starts_with("Async functions are") | ||
| || msg.starts_with("Async for loops are") | ||
| || msg.starts_with("Async with statements are") | ||
|
|
@@ -820,12 +830,14 @@ impl VirtualMachine { | |
|
|
||
| // Set end_lineno and end_offset if available | ||
| if let Some((end_lineno, end_offset)) = error.python_end_location() { | ||
| let (end_lineno, end_offset) = if check_version_suite_error | ||
| && statement | ||
| .as_deref() | ||
| .and_then(|line| line.chars().next()) | ||
| .is_some_and(|ch| ch.is_ascii_whitespace()) | ||
| { | ||
| // EOF errors have no source span in CPython. | ||
| let no_end_offset = unexpected_eof_error | ||
| || (check_version_suite_error | ||
| && statement | ||
| .as_deref() | ||
| .and_then(|line| line.chars().next()) | ||
| .is_some_and(|ch| ch.is_ascii_whitespace())); | ||
| let (end_lineno, end_offset) = if no_end_offset { | ||
| (end_lineno, -1) | ||
| } else if line_end_binary_operator_error && end_offset == offset_raw { | ||
| (end_lineno, (end_offset + 1) as isize) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.