mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-13 15:18:06 +00: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:
parent
eb9a1bc5f1
commit
e80260a3c5
45 changed files with 623 additions and 714 deletions
|
@ -137,7 +137,7 @@ pub fn format_module_source(
|
|||
) -> Result<Printed, FormatModuleError> {
|
||||
let source_type = options.source_type();
|
||||
let (tokens, comment_ranges) = tokens_and_ranges(source, source_type)?;
|
||||
let module = parse_ok_tokens(tokens, source, source_type.as_mode(), "<filename>")?;
|
||||
let module = parse_ok_tokens(tokens, source, source_type.as_mode())?;
|
||||
let formatted = format_module_ast(&module, &comment_ranges, source, options)?;
|
||||
Ok(formatted.print()?)
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ def main() -> None:
|
|||
|
||||
// Parse the AST.
|
||||
let source_path = "code_inline.py";
|
||||
let module = parse_ok_tokens(tokens, source, source_type.as_mode(), source_path).unwrap();
|
||||
let module = parse_ok_tokens(tokens, source, source_type.as_mode()).unwrap();
|
||||
let options = PyFormatOptions::from_extension(Path::new(source_path));
|
||||
let formatted = format_module_ast(&module, &comment_ranges, source, options).unwrap();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue