Remove type parameter from parse_* methods (#9466)

This commit is contained in:
Micha Reiser 2024-01-11 19:41:19 +01:00 committed by GitHub
parent 25bafd2d66
commit f192c72596
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 98 additions and 84 deletions

View file

@ -8,7 +8,7 @@ use clap::{command, Parser, ValueEnum};
use ruff_formatter::SourceCode;
use ruff_python_ast::PySourceType;
use ruff_python_index::tokens_and_ranges;
use ruff_python_parser::{parse_ok_tokens, AsMode};
use ruff_python_parser::{parse_tokens, AsMode};
use ruff_text_size::Ranged;
use crate::comments::collect_comments;
@ -51,7 +51,7 @@ pub fn format_and_debug_print(source: &str, cli: &Cli, source_path: &Path) -> Re
// Parse the AST.
let module =
parse_ok_tokens(tokens, source, source_type.as_mode()).context("Syntax error in input")?;
parse_tokens(tokens, source, source_type.as_mode()).context("Syntax error in input")?;
let options = PyFormatOptions::from_extension(source_path)
.with_preview(if cli.preview {

View file

@ -102,12 +102,12 @@ use ruff_python_ast::Mod;
use ruff_python_trivia::{CommentRanges, PythonWhitespace};
use ruff_source_file::Locator;
use ruff_text_size::{Ranged, TextRange};
pub(crate) use visitor::collect_comments;
use crate::comments::debug::{DebugComment, DebugComments};
use crate::comments::map::{LeadingDanglingTrailing, MultiMap};
use crate::comments::node_key::NodeRefEqualityKey;
use crate::comments::visitor::{CommentsMapBuilder, CommentsVisitor};
pub(crate) use visitor::collect_comments;
mod debug;
pub(crate) mod format;
@ -563,8 +563,7 @@ mod tests {
use ruff_formatter::SourceCode;
use ruff_python_ast::{Mod, PySourceType};
use ruff_python_index::tokens_and_ranges;
use ruff_python_parser::{parse_ok_tokens, AsMode};
use ruff_python_parser::{parse_tokens, AsMode};
use ruff_python_trivia::CommentRanges;
use crate::comments::Comments;
@ -581,7 +580,7 @@ mod tests {
let source_type = PySourceType::Python;
let (tokens, comment_ranges) =
tokens_and_ranges(source, source_type).expect("Expect source to be valid Python");
let parsed = parse_ok_tokens(tokens, source, source_type.as_mode())
let parsed = parse_tokens(tokens, source, source_type.as_mode())
.expect("Expect source to be valid Python");
CommentsTestCase {

View file

@ -6,7 +6,7 @@ use ruff_formatter::{format, FormatError, Formatted, PrintError, Printed, Source
use ruff_python_ast::AstNode;
use ruff_python_ast::Mod;
use ruff_python_index::tokens_and_ranges;
use ruff_python_parser::{parse_ok_tokens, AsMode, ParseError, ParseErrorType};
use ruff_python_parser::{parse_tokens, AsMode, ParseError, ParseErrorType};
use ruff_python_trivia::CommentRanges;
use ruff_source_file::Locator;
@ -126,7 +126,7 @@ pub fn format_module_source(
offset: err.location,
error: ParseErrorType::Lexical(err.error),
})?;
let module = parse_ok_tokens(tokens, source, source_type.as_mode())?;
let module = parse_tokens(tokens, source, source_type.as_mode())?;
let formatted = format_module_ast(&module, &comment_ranges, source, options)?;
Ok(formatted.print()?)
}
@ -169,7 +169,7 @@ mod tests {
use ruff_python_ast::PySourceType;
use ruff_python_index::tokens_and_ranges;
use ruff_python_parser::{parse_ok_tokens, AsMode};
use ruff_python_parser::{parse_tokens, AsMode};
use crate::{format_module_ast, format_module_source, PyFormatOptions};
@ -213,7 +213,7 @@ def main() -> None:
// Parse the AST.
let source_path = "code_inline.py";
let module = parse_ok_tokens(tokens, source, source_type.as_mode()).unwrap();
let module = parse_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();

View file

@ -1516,7 +1516,7 @@ fn docstring_format_source(
let source_type = options.source_type();
let (tokens, comment_ranges) =
ruff_python_index::tokens_and_ranges(source, source_type).map_err(ParseError::from)?;
let module = ruff_python_parser::parse_ok_tokens(tokens, source, source_type.as_mode())?;
let module = ruff_python_parser::parse_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);