mirror of
https://github.com/astral-sh/ruff
synced 2026-01-21 21:40:51 -05:00
Remove source path from parser errors (#9322)
## Summary I always found it odd that we had to pass this in, since it's really higher-level context for the error. The awkwardness is further evidenced by the fact that we pass in fake values everywhere (even outside of tests). The source path isn't actually used to display the error; it's only accessed elsewhere to _re-display_ the error in certain cases. This PR modifies to instead pass the path directly in those cases.
This commit is contained in:
@@ -524,11 +524,7 @@ impl<'ast, 'buf, 'fmt, 'src> DocstringLinePrinter<'ast, 'buf, 'fmt, 'src> {
|
||||
std::format!(r#""""{}""""#, printed.as_code())
|
||||
}
|
||||
};
|
||||
let result = ruff_python_parser::parse(
|
||||
&wrapped,
|
||||
self.f.options().source_type().as_mode(),
|
||||
"<filename>",
|
||||
);
|
||||
let result = ruff_python_parser::parse(&wrapped, self.f.options().source_type().as_mode());
|
||||
// If the resulting code is not valid, then reset and pass through
|
||||
// the docstring lines as-is.
|
||||
if result.is_err() {
|
||||
@@ -1523,8 +1519,7 @@ fn docstring_format_source(
|
||||
|
||||
let source_type = options.source_type();
|
||||
let (tokens, comment_ranges) = ruff_python_index::tokens_and_ranges(source, source_type)?;
|
||||
let module =
|
||||
ruff_python_parser::parse_ok_tokens(tokens, source, source_type.as_mode(), "<filename>")?;
|
||||
let module = ruff_python_parser::parse_ok_tokens(tokens, source, source_type.as_mode())?;
|
||||
let source_code = ruff_formatter::SourceCode::new(source);
|
||||
let comments = crate::Comments::from_ast(&module, source_code, &comment_ranges);
|
||||
let locator = Locator::new(source);
|
||||
|
||||
Reference in New Issue
Block a user