FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Take SyntaxError messages and ranges from the parser by youknowone · Pull Request #8983 · RustPython/RustPython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
776ab5d
Match CPython's SyntaxError range for unparenthesized `except` types
zzarbttoo Sep 6, 2026
e491d0d
Clarify that the `except` error range stops before the closing colon
zzarbttoo Sep 20, 2026
abacad2
Fix the `except ... as` error column for non-ASCII names and line joins
zzarbttoo Sep 20, 2026
5931324
Update the Ruff fork to 0.16.10
youknowone Oct 4, 2026
264650b
Drop the source scan for the `except ... as` error range
youknowone Oct 4, 2026
c1ed646
Take parse error messages from the parser as they are
youknowone Oct 4, 2026
fe81dff
Take starred and bytes literal error ranges from the parser
youknowone Oct 4, 2026
718e61a
Take indentation error kinds and positions from the parser
youknowone Oct 4, 2026
645631b
Take unterminated string messages from the parser
youknowone Oct 4, 2026
8f74913
Take bracket errors and tokenizer error priority from the parser
youknowone Oct 4, 2026
61b4032
Take number literal, string prefix and non-printable errors from the …
youknowone Oct 4, 2026
efe3856
Take the missing indented block error from the parser
youknowone Oct 4, 2026
b4660b4
Take binding target errors from the parser
youknowone Oct 4, 2026
2523208
Take parameter, argument, star, comma and dictionary errors from the …
youknowone Oct 4, 2026
13f1a00
Take expression errors from the parser
youknowone Oct 4, 2026
a47ad11
Take statement errors from the parser
youknowone Oct 5, 2026
450242a
Take string and f-string errors from the parser
youknowone Oct 5, 2026
f5af0dd
Restore the bracket depth check and fix incomplete unclosed strings
youknowone Oct 6, 2026
8cfafa1
Report multiple statements before later errors in single mode
youknowone Oct 6, 2026
a099d0b
Update the Ruff fork for parser speed and starred annotations
youknowone Oct 6, 2026
820917a
Use the published Ruff fork 0.16.10 crates
youknowone Oct 7, 2026
File filter

Filter by extension

Filter by extension .lock  (1) .rs  (2) .toml  (1) All 3 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Prev Previous commit
Next Next commit
Take starred and bytes literal error ranges from the parser
The Ruff fork now reports misplaced starred expressions at the `*` and
non-ASCII bytes literal errors over the whole literal. `vm_new.rs` drops
`narrow_caret` together with `SyntaxErrorInfo`, which only carried the
message after that, and the compiler drops `bytes_literal_span`.

Assisted-by: Claude Code:claude-opus-5-5
  • Loading branch information
youknowone committed Oct 4, 2026
commit fe81dff0b090d3d4da65e22d3bcd14250e782e5e
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ rustpython-wtf8 = { path = "crates/wtf8", version = "0.6.1" }
rustpython-doc = { path = "crates/doc", version = "0.6.1" }

# Use the RustPython Ruff fork for RustPython public `_ast` metadata.
ruff_python_parser = { package = "rustpython-ruff_python_parser", git = "https://github.com/RustPython/ruff.git", rev = "be649be9ba1d41d6913099cfc52b59c5be9b5371" }
ruff_python_ast = { package = "rustpython-ruff_python_ast", git = "https://github.com/RustPython/ruff.git", rev = "be649be9ba1d41d6913099cfc52b59c5be9b5371" }
ruff_text_size = { package = "rustpython-ruff_text_size", git = "https://github.com/RustPython/ruff.git", rev = "be649be9ba1d41d6913099cfc52b59c5be9b5371" }
ruff_source_file = { package = "rustpython-ruff_source_file", git = "https://github.com/RustPython/ruff.git", rev = "be649be9ba1d41d6913099cfc52b59c5be9b5371" }
ruff_python_parser = { package = "rustpython-ruff_python_parser", git = "https://github.com/RustPython/ruff.git", rev = "c66aaf408f868b9de162b06dad66442c57d121c6" }
ruff_python_ast = { package = "rustpython-ruff_python_ast", git = "https://github.com/RustPython/ruff.git", rev = "c66aaf408f868b9de162b06dad66442c57d121c6" }
ruff_text_size = { package = "rustpython-ruff_text_size", git = "https://github.com/RustPython/ruff.git", rev = "c66aaf408f868b9de162b06dad66442c57d121c6" }
ruff_source_file = { package = "rustpython-ruff_source_file", git = "https://github.com/RustPython/ruff.git", rev = "c66aaf408f868b9de162b06dad66442c57d121c6" }

der = { version = "0.8", features = ["alloc", "oid", "pem", "zeroize"] }
phf = { version = "0.14.0", default-features = false, features = ["macros"]}
Expand Down
44 changes: 0 additions & 44 deletions crates/compiler/src/lib.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -478,24 +478,6 @@ fn cpython_parse_diagnostic_override(
source_error!(mixed_except_handlers_error(source_text));
}

if matches!(
&error.error,
parser::ParseErrorType::Lexical(parser::LexicalErrorType::InvalidByteLiteral)
) && let Some((start, end)) =
bytes_literal_span(source_text, error.location.start().to_usize())
{
let (loc, end_loc) = source_locations(
source_file,
TextSize::new(start as u32),
TextSize::new(end as u32),
);
return Some(NormalizedParseDiagnostic::new(
error.error.clone(),
loc,
end_loc,
));
}

if matches!(
&error.error,
parser::ParseErrorType::Lexical(parser::LexicalErrorType::IndentationError)
Expand Down Expand Up @@ -981,32 +963,6 @@ fn quoted_string_is_closed(bytes: &[u8], start: usize) -> bool {
}
}

fn bytes_literal_span(source: &str, error_at: usize) -> Option<(usize, usize)> {
let bytes = source.as_bytes();
if error_at > bytes.len() || bytes.is_empty() {
return None;
}
let mut quote_idx = error_at.min(bytes.len().saturating_sub(1));
loop {
if matches!(bytes[quote_idx], b'\'' | b'"') {
break;
}
if quote_idx == 0 {
return None;
}
quote_idx -= 1;
}
let mut start = quote_idx;
while start > 0 && matches!(bytes[start - 1], b'b' | b'B' | b'r' | b'R') {
start -= 1;
}
if !matches!(bytes.get(start), Some(b'b' | b'B' | b'r' | b'R')) {
return None;
}
let end = skip_quoted_string(bytes, quote_idx);
Some((start, end))
}

fn skip_quoted_string(bytes: &[u8], mut index: usize) -> usize {
let quote = bytes[index];
let triple = bytes.get(index + 1) == Some(&quote) && bytes.get(index + 2) == Some(&quote);
Expand Down
75 changes: 17 additions & 58 deletions crates/vm/src/vm/vm_new.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustpython_compiler_core::SourceLocation;
use core::ops::RangeInclusive;

#[cfg(feature = "parser")]
use rustpython_compiler::{CompileError, ParseError, is_blank_python_source};
use rustpython_compiler::is_blank_python_source;

use crate::{
AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
Expand Down Expand Up @@ -47,43 +47,6 @@ macro_rules! define_exception_fn {
};
}

#[derive(Clone, Debug)]
struct SyntaxErrorInfo {
msg: String,
narrow_caret: bool,
}

impl SyntaxErrorInfo {
#[must_use]
const fn new(msg: String, narrow_caret: bool) -> Self {
Self { msg, narrow_caret }
}

#[cfg(feature = "parser")]
fn analyze_compile_error(&mut self, compile_error: &CompileError) {
let CompileError::Parse(ParseError {
error, location, ..
}) = compile_error
else {
return;
};

match error {
ParseErrorType::InvalidStarredExpressionUsage
| ParseErrorType::InvalidStarPatternUsage => self.narrow_caret = true,

ParseErrorType::Lexical(LexicalErrorType::UnclosedStringError) => {
self.msg = format!(
"unterminated string literal (detected at line {})",
location.line
);
}

_ => {}
}
}
}

/// Collection of object creation helpers
impl VirtualMachine {
/// Create a new python object
Expand Down Expand Up @@ -685,26 +648,25 @@ impl VirtualMachine {
source.and_then(|src| get_statement(src, error.location()))
};

let msg = error.to_string();

cfg_select! {
feature = "parser" => {
let mut syntax_error_info = SyntaxErrorInfo::new(msg, false);
syntax_error_info.analyze_compile_error(error);
}
_ => {
let syntax_error_info = SyntaxErrorInfo::new(msg, false);
let msg = if syntax_error_type.is(self.ctx.exceptions.tab_error) {
String::from("inconsistent use of tabs and spaces in indentation")
} else if syntax_error_type.is(self.ctx.exceptions.incomplete_input_error) {
String::from("incomplete input")
} else {
match error {
#[cfg(feature = "parser")]
crate::compiler::CompileError::Parse(rustpython_compiler::ParseError {
error: ParseErrorType::Lexical(LexicalErrorType::UnclosedStringError),
location,
..
}) => format!(
"unterminated string literal (detected at line {})",
location.line
),
_ => error.to_string(),
}
};

if syntax_error_type.is(self.ctx.exceptions.tab_error) {
syntax_error_info.msg =
String::from("inconsistent use of tabs and spaces in indentation");
} else if syntax_error_type.is(self.ctx.exceptions.incomplete_input_error) {
syntax_error_info.msg = String::from("incomplete input");
}

let SyntaxErrorInfo { msg, narrow_caret } = syntax_error_info;
let unterminated_triple_quoted_string = msg.starts_with("unterminated triple-quoted");
let unexpected_eof_error = msg == "unexpected EOF while parsing";
if unterminated_triple_quoted_string
Expand Down Expand Up @@ -768,9 +730,6 @@ impl VirtualMachine {
(end_lineno, 0)
} else if line_end_binary_operator_error && end_offset == offset_raw {
(end_lineno, (end_offset + 1) as isize)
} else if narrow_caret {
let (l, o) = error.python_location();
(l, (o + 1) as isize)
} else {
(end_lineno, end_offset as isize)
};
Expand Down

Back | FazBrowse Home | New Git URL