Remove parser dependency from ruff-python-ast (#6096)

This commit is contained in:
Micha Reiser 2023-07-26 17:47:22 +02:00 committed by GitHub
parent 99127243f4
commit 2cf00fee96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
658 changed files with 1714 additions and 1546 deletions

View file

@ -1,5 +1,5 @@
use ruff_text_size::{TextRange, TextSize};
use rustpython_parser::ast::Ranged;
use rustpython_ast::Ranged;
use crate::comments::{dangling_comments, SourceComment};
use ruff_formatter::{format_args, write, Argument, Arguments};
@ -377,7 +377,7 @@ impl<'ast> Format<PyFormatContext<'ast>> for EmptyWithDanglingComments<'_> {
#[cfg(test)]
mod tests {
use rustpython_parser::ast::ModModule;
use rustpython_ast::ModModule;
use rustpython_parser::Parse;
use ruff_formatter::format;

View file

@ -8,7 +8,7 @@ use rustpython_parser::lexer::lex;
use rustpython_parser::{parse_tokens, Mode};
use ruff_formatter::SourceCode;
use ruff_python_ast::source_code::CommentRangesBuilder;
use ruff_python_index::CommentRangesBuilder;
use crate::{format_node, PyFormatOptions};

View file

@ -1,7 +1,7 @@
use std::fmt::{Debug, Formatter, Write};
use itertools::Itertools;
use rustpython_parser::ast::Ranged;
use rustpython_ast::Ranged;
use ruff_formatter::SourceCode;
@ -179,7 +179,7 @@ impl Debug for DebugNodeCommentSlice<'_> {
mod tests {
use insta::assert_debug_snapshot;
use ruff_text_size::{TextRange, TextSize};
use rustpython_parser::ast::{StmtBreak, StmtContinue};
use rustpython_ast::{StmtBreak, StmtContinue};
use ruff_formatter::SourceCode;
use ruff_python_ast::node::AnyNode;

View file

@ -1,5 +1,5 @@
use ruff_text_size::{TextLen, TextRange, TextSize};
use rustpython_parser::ast::Ranged;
use rustpython_ast::Ranged;
use ruff_formatter::{format_args, write, FormatError, SourceCode};
use ruff_python_ast::node::{AnyNodeRef, AstNode};

View file

@ -92,7 +92,7 @@ use std::cell::Cell;
use std::fmt::Debug;
use std::rc::Rc;
use rustpython_parser::ast::{Mod, Ranged};
use rustpython_ast::{Mod, Ranged};
pub(crate) use format::{
dangling_comments, dangling_node_comments, leading_alternate_branch_comments, leading_comments,
@ -100,7 +100,7 @@ pub(crate) use format::{
};
use ruff_formatter::{SourceCode, SourceCodeSlice};
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::source_code::CommentRanges;
use ruff_python_index::CommentRanges;
use crate::comments::debug::{DebugComment, DebugComments};
use crate::comments::map::MultiMap;
@ -414,12 +414,12 @@ struct CommentsData<'a> {
#[cfg(test)]
mod tests {
use insta::assert_debug_snapshot;
use rustpython_parser::ast::Mod;
use rustpython_ast::Mod;
use rustpython_parser::lexer::lex;
use rustpython_parser::{parse_tokens, Mode};
use ruff_formatter::SourceCode;
use ruff_python_ast::source_code::{CommentRanges, CommentRangesBuilder};
use ruff_python_index::{CommentRanges, CommentRangesBuilder};
use crate::comments::Comments;

View file

@ -54,7 +54,7 @@ mod tests {
use crate::comments::node_key::NodeRefEqualityKey;
use ruff_python_ast::node::AnyNodeRef;
use ruff_text_size::TextRange;
use rustpython_parser::ast::StmtContinue;
use rustpython_ast::StmtContinue;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};

View file

@ -1,15 +1,15 @@
use std::cmp::Ordering;
use ruff_text_size::TextRange;
use rustpython_ast::{Expr, ExprIfExp, ExprSlice, Ranged};
use rustpython_parser::ast;
use rustpython_parser::ast::{Expr, ExprIfExp, ExprSlice, Ranged};
use ruff_python_ast::node::{AnyNodeRef, AstNode};
use ruff_python_ast::source_code::Locator;
use ruff_python_ast::whitespace;
use ruff_python_trivia::{
PythonWhitespace, SimpleToken, SimpleTokenKind, SimpleTokenizer, UniversalNewlines,
indentation_at_offset, PythonWhitespace, SimpleToken, SimpleTokenKind, SimpleTokenizer,
};
use ruff_source_file::{Locator, UniversalNewlines};
use crate::comments::visitor::{CommentPlacement, DecoratedComment};
use crate::expression::expr_slice::{assign_comment_in_slice, ExprSliceCommentSection};
@ -89,10 +89,9 @@ fn handle_match_comment<'a>(
let next_case = match_stmt.cases.get(current_case_index + 1);
let comment_indentation =
whitespace::indentation_at_offset(locator, comment.slice().range().start())
.unwrap_or_default()
.len();
let comment_indentation = indentation_at_offset(locator, comment.slice().range().start())
.unwrap_or_default()
.len();
let match_case_indentation = whitespace::indentation(locator, match_case).unwrap().len();
if let Some(next_case) = next_case {
@ -174,10 +173,9 @@ fn handle_in_between_except_handlers_or_except_handler_and_else_or_finally_comme
// it now depends on the indentation level of the comment if it is a leading comment for e.g.
// the following `finally` or indeed a trailing comment of the previous body's last statement.
let comment_indentation =
whitespace::indentation_at_offset(locator, comment.slice().range().start())
.unwrap_or_default()
.len();
let comment_indentation = indentation_at_offset(locator, comment.slice().range().start())
.unwrap_or_default()
.len();
let Some(except_indentation) =
whitespace::indentation(locator, preceding_except_handler).map(str::len)
@ -269,10 +267,9 @@ fn handle_in_between_bodies_own_line_comment<'a>(
// it now depends on the indentation level of the comment if it is a leading comment for e.g.
// the following `elif` or indeed a trailing comment of the previous body's last statement.
let comment_indentation =
whitespace::indentation_at_offset(locator, comment.slice().range().start())
.unwrap_or_default()
.len();
let comment_indentation = indentation_at_offset(locator, comment.slice().range().start())
.unwrap_or_default()
.len();
let Some(preceding_indentation) = whitespace::indentation(locator, &preceding).map(str::len)
else {
@ -445,10 +442,9 @@ fn own_line_comment_after_branch<'a>(
// We only care about the length because indentations with mixed spaces and tabs are only valid if
// the indent-level doesn't depend on the tab width (the indent level must be the same if the tab width is 1 or 8).
let comment_indentation =
whitespace::indentation_at_offset(locator, comment.slice().range().start())
.unwrap_or_default()
.len();
let comment_indentation = indentation_at_offset(locator, comment.slice().range().start())
.unwrap_or_default()
.len();
// Keep the comment on the entire statement in case it's a trailing comment
// ```python
@ -459,10 +455,9 @@ fn own_line_comment_after_branch<'a>(
// # Trailing if comment
// ```
// Here we keep the comment a trailing comment of the `if`
let preceding_node_indentation =
whitespace::indentation_at_offset(locator, preceding_node.start())
.unwrap_or_default()
.len();
let preceding_node_indentation = indentation_at_offset(locator, preceding_node.start())
.unwrap_or_default()
.len();
if comment_indentation == preceding_node_indentation {
return CommentPlacement::Default(comment);
}

View file

@ -1,14 +1,15 @@
use std::iter::Peekable;
use ruff_text_size::{TextRange, TextSize};
use rustpython_parser::ast::{
use rustpython_ast::{
Alias, Arg, ArgWithDefault, Arguments, Comprehension, Decorator, ElifElseClause, ExceptHandler,
Expr, Keyword, MatchCase, Mod, Pattern, Ranged, Stmt, TypeParam, WithItem,
};
use ruff_formatter::{SourceCode, SourceCodeSlice};
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::source_code::{CommentRanges, Locator};
use ruff_python_index::CommentRanges;
use ruff_source_file::Locator;
// The interface is designed to only export the members relevant for iterating nodes in
// pre-order.
#[allow(clippy::wildcard_imports)]

View file

@ -1,7 +1,7 @@
use crate::comments::Comments;
use crate::PyFormatOptions;
use ruff_formatter::{FormatContext, GroupId, SourceCode};
use ruff_python_ast::source_code::Locator;
use ruff_source_file::Locator;
use std::fmt::{Debug, Formatter};
#[derive(Clone)]

View file

@ -1,4 +1,4 @@
use rustpython_parser::ast::{Constant, Expr, ExprAttribute, ExprConstant};
use rustpython_ast::{Constant, Expr, ExprAttribute, ExprConstant};
use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef;

View file

@ -1,4 +1,4 @@
use rustpython_parser::ast::ExprAwait;
use rustpython_ast::ExprAwait;
use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef;

View file

@ -1,6 +1,6 @@
use std::iter;
use rustpython_parser::ast::{
use rustpython_ast::{
Constant, Expr, ExprAttribute, ExprBinOp, ExprConstant, ExprUnaryOp, Operator, UnaryOp,
};
use smallvec::SmallVec;

View file

@ -6,7 +6,7 @@ use crate::expression::parentheses::{
use crate::prelude::*;
use ruff_formatter::{write, FormatOwnedWithRule, FormatRefWithRule, FormatRuleWithOptions};
use ruff_python_ast::node::AnyNodeRef;
use rustpython_parser::ast::{BoolOp, ExprBoolOp};
use rustpython_ast::{BoolOp, ExprBoolOp};
#[derive(Default)]
pub struct FormatExprBoolOp {

View file

@ -1,5 +1,5 @@
use ruff_text_size::{TextRange, TextSize};
use rustpython_parser::ast::{Expr, ExprCall, Ranged};
use rustpython_ast::{Expr, ExprCall, Ranged};
use crate::builders::empty_parenthesized_with_dangling_comments;
use ruff_formatter::write;

View file

@ -7,7 +7,7 @@ use crate::prelude::*;
use crate::FormatNodeRule;
use ruff_formatter::{write, FormatOwnedWithRule, FormatRefWithRule, FormatRuleWithOptions};
use ruff_python_ast::node::AnyNodeRef;
use rustpython_parser::ast::{CmpOp, ExprCompare};
use rustpython_ast::{CmpOp, ExprCompare};
#[derive(Default)]
pub struct FormatExprCompare {

View file

@ -1,5 +1,5 @@
use ruff_text_size::{TextLen, TextRange};
use rustpython_parser::ast::{Constant, ExprConstant, Ranged};
use rustpython_ast::{Constant, ExprConstant, Ranged};
use ruff_formatter::FormatRuleWithOptions;
use ruff_python_ast::node::AnyNodeRef;

View file

@ -6,8 +6,8 @@ use crate::FormatNodeRule;
use ruff_formatter::{format_args, write};
use ruff_python_ast::node::AnyNodeRef;
use ruff_text_size::TextRange;
use rustpython_parser::ast::Ranged;
use rustpython_parser::ast::{Expr, ExprDict};
use rustpython_ast::Ranged;
use rustpython_ast::{Expr, ExprDict};
#[derive(Default)]
pub struct FormatExprDict;

View file

@ -7,7 +7,7 @@ use ruff_formatter::prelude::{
};
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::node::AnyNodeRef;
use rustpython_parser::ast::ExprDictComp;
use rustpython_ast::ExprDictComp;
#[derive(Default)]
pub struct FormatExprDictComp;

View file

@ -3,7 +3,7 @@ use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::node::AnyNodeRef;
use rustpython_parser::ast::ExprFormattedValue;
use rustpython_ast::ExprFormattedValue;
#[derive(Default)]
pub struct FormatExprFormattedValue;

View file

@ -6,7 +6,7 @@ use crate::AsFormat;
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::{format_args, write, Buffer, FormatResult, FormatRuleWithOptions};
use ruff_python_ast::node::AnyNodeRef;
use rustpython_parser::ast::ExprGeneratorExp;
use rustpython_ast::ExprGeneratorExp;
#[derive(Eq, PartialEq, Debug, Default)]
pub enum GeneratorExpParentheses {

View file

@ -7,7 +7,7 @@ use crate::prelude::*;
use crate::FormatNodeRule;
use ruff_formatter::{format_args, write};
use ruff_python_ast::node::AnyNodeRef;
use rustpython_parser::ast::ExprIfExp;
use rustpython_ast::ExprIfExp;
#[derive(Default)]
pub struct FormatExprIfExp;

View file

@ -3,7 +3,7 @@ use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::node::AnyNodeRef;
use rustpython_parser::ast::ExprJoinedStr;
use rustpython_ast::ExprJoinedStr;
#[derive(Default)]
pub struct FormatExprJoinedStr;

View file

@ -7,7 +7,7 @@ use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::{space, text};
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::node::AnyNodeRef;
use rustpython_parser::ast::ExprLambda;
use rustpython_ast::ExprLambda;
#[derive(Default)]
pub struct FormatExprLambda;

View file

@ -3,7 +3,7 @@ use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalPa
use crate::prelude::*;
use crate::FormatNodeRule;
use ruff_python_ast::node::AnyNodeRef;
use rustpython_parser::ast::{ExprList, Ranged};
use rustpython_ast::{ExprList, Ranged};
#[derive(Default)]
pub struct FormatExprList;

View file

@ -5,7 +5,7 @@ use crate::AsFormat;
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::{format_args, write, Buffer, FormatResult};
use ruff_python_ast::node::AnyNodeRef;
use rustpython_parser::ast::ExprListComp;
use rustpython_ast::ExprListComp;
#[derive(Default)]
pub struct FormatExprListComp;

View file

@ -3,7 +3,7 @@ use crate::prelude::*;
use crate::FormatNodeRule;
use ruff_formatter::{write, FormatContext};
use ruff_python_ast::node::AnyNodeRef;
use rustpython_parser::ast::ExprName;
use rustpython_ast::ExprName;
#[derive(Default)]
pub struct FormatExprName;
@ -37,7 +37,7 @@ impl NeedsParentheses for ExprName {
#[cfg(test)]
mod tests {
use ruff_text_size::{TextRange, TextSize};
use rustpython_parser::ast::{ModModule, Ranged};
use rustpython_ast::{ModModule, Ranged};
use rustpython_parser::Parse;
#[test]

View file

@ -4,7 +4,7 @@ use crate::{AsFormat, FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::{space, text};
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::node::AnyNodeRef;
use rustpython_parser::ast::ExprNamedExpr;
use rustpython_ast::ExprNamedExpr;
#[derive(Default)]
pub struct FormatExprNamedExpr;

View file

@ -1,4 +1,4 @@
use rustpython_parser::ast::{ExprSet, Ranged};
use rustpython_ast::{ExprSet, Ranged};
use ruff_python_ast::node::AnyNodeRef;

View file

@ -5,7 +5,7 @@ use crate::AsFormat;
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::{format_args, write, Buffer, FormatResult};
use ruff_python_ast::node::AnyNodeRef;
use rustpython_parser::ast::ExprSetComp;
use rustpython_ast::ExprSetComp;
#[derive(Default)]
pub struct FormatExprSetComp;

View file

@ -1,5 +1,5 @@
use ruff_text_size::TextRange;
use rustpython_parser::ast::{Expr, ExprSlice, ExprUnaryOp, Ranged, UnaryOp};
use rustpython_ast::{Expr, ExprSlice, ExprUnaryOp, Ranged, UnaryOp};
use ruff_formatter::prelude::{hard_line_break, line_suffix_boundary, space, text};
use ruff_formatter::{write, Buffer, Format, FormatError, FormatResult};

View file

@ -1,4 +1,4 @@
use rustpython_parser::ast::ExprStarred;
use rustpython_ast::ExprStarred;
use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef;

View file

@ -1,4 +1,4 @@
use rustpython_parser::ast::{Expr, ExprSubscript};
use rustpython_ast::{Expr, ExprSubscript};
use ruff_formatter::{format_args, write};
use ruff_python_ast::node::{AnyNodeRef, AstNode};

View file

@ -1,6 +1,6 @@
use ruff_text_size::TextRange;
use rustpython_parser::ast::ExprTuple;
use rustpython_parser::ast::{Expr, Ranged};
use rustpython_ast::ExprTuple;
use rustpython_ast::{Expr, Ranged};
use ruff_formatter::{format_args, write, FormatRuleWithOptions};
use ruff_python_ast::node::AnyNodeRef;

View file

@ -1,6 +1,6 @@
use ruff_text_size::{TextLen, TextRange};
use rustpython_parser::ast::UnaryOp;
use rustpython_parser::ast::{ExprUnaryOp, Ranged};
use rustpython_ast::UnaryOp;
use rustpython_ast::{ExprUnaryOp, Ranged};
use ruff_formatter::prelude::{hard_line_break, space, text};
use ruff_formatter::{Format, FormatContext, FormatResult};

View file

@ -5,7 +5,7 @@ use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::{space, text};
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::node::AnyNodeRef;
use rustpython_parser::ast::ExprYield;
use rustpython_ast::ExprYield;
#[derive(Default)]
pub struct FormatExprYield;

View file

@ -5,7 +5,7 @@ use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::{space, text};
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::node::AnyNodeRef;
use rustpython_parser::ast::ExprYieldFrom;
use rustpython_ast::ExprYieldFrom;
#[derive(Default)]
pub struct FormatExprYieldFrom;

View file

@ -1,7 +1,7 @@
use std::cmp::Ordering;
use rustpython_ast::{Expr, Operator};
use rustpython_parser::ast;
use rustpython_parser::ast::{Expr, Operator};
use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule, FormatRule, FormatRuleWithOptions};
use ruff_python_ast::node::AnyNodeRef;

View file

@ -1,7 +1,7 @@
use std::borrow::Cow;
use ruff_text_size::TextSize;
use rustpython_parser::ast::{ExprConstant, Ranged};
use rustpython_ast::{ExprConstant, Ranged};
use crate::prelude::*;

View file

@ -1,4 +1,4 @@
use rustpython_parser::ast::Ranged;
use rustpython_ast::Ranged;
use ruff_formatter::prelude::tag::Condition;
use ruff_formatter::{format_args, write, Argument, Arguments};

View file

@ -2,7 +2,7 @@ use std::borrow::Cow;
use bitflags::bitflags;
use ruff_text_size::{TextLen, TextRange, TextSize};
use rustpython_parser::ast::{ExprConstant, Ranged};
use rustpython_ast::{ExprConstant, Ranged};
use rustpython_parser::lexer::{lex_starts_at, LexicalError, LexicalErrorType};
use rustpython_parser::{Mode, Tok};

View file

@ -13,9 +13,10 @@ use ruff_formatter::{
};
use ruff_formatter::{Formatted, Printed, SourceCode};
use ruff_python_ast::node::{AnyNodeRef, AstNode, NodeKind};
use ruff_python_ast::source_code::{CommentRanges, CommentRangesBuilder, Locator};
use ruff_python_index::{CommentRanges, CommentRangesBuilder};
use ruff_source_file::Locator;
use ruff_text_size::{TextLen, TextRange};
use rustpython_parser::ast::{Mod, Ranged};
use rustpython_ast::{Mod, Ranged};
use rustpython_parser::lexer::{lex, LexicalError};
use rustpython_parser::{parse_tokens, Mode, ParseError};
use std::borrow::Cow;
@ -249,7 +250,7 @@ mod tests {
use crate::{format_module, format_node, PyFormatOptions};
use anyhow::Result;
use insta::assert_snapshot;
use ruff_python_ast::source_code::CommentRangesBuilder;
use ruff_python_index::CommentRangesBuilder;
use rustpython_parser::lexer::lex;
use rustpython_parser::{parse_tokens, Mode};

View file

@ -1,7 +1,7 @@
use crate::context::PyFormatContext;
use crate::{AsFormat, IntoFormat, PyFormatter};
use ruff_formatter::{Format, FormatOwnedWithRule, FormatRefWithRule, FormatResult, FormatRule};
use rustpython_parser::ast::Mod;
use rustpython_ast::Mod;
pub(crate) mod mod_expression;
pub(crate) mod mod_function_type;

View file

@ -1,6 +1,6 @@
use crate::{AsFormat, FormatNodeRule, PyFormatter};
use ruff_formatter::{Format, FormatResult};
use rustpython_parser::ast::ModExpression;
use rustpython_ast::ModExpression;
#[derive(Default)]
pub struct FormatModExpression;

View file

@ -1,6 +1,6 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::ModFunctionType;
use rustpython_ast::ModFunctionType;
#[derive(Default)]
pub struct FormatModFunctionType;

View file

@ -1,6 +1,6 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::ModInteractive;
use rustpython_ast::ModInteractive;
#[derive(Default)]
pub struct FormatModInteractive;

View file

@ -2,7 +2,7 @@ use crate::statement::suite::SuiteLevel;
use crate::{AsFormat, FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::hard_line_break;
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::ModModule;
use rustpython_ast::ModModule;
#[derive(Default)]
pub struct FormatModModule;

View file

@ -1,7 +1,7 @@
use crate::{AsFormat, FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::{space, text};
use ruff_formatter::{write, Buffer, Format, FormatResult};
use rustpython_parser::ast::Alias;
use rustpython_ast::Alias;
#[derive(Default)]
pub struct FormatAlias;

View file

@ -1,7 +1,7 @@
use crate::prelude::*;
use crate::FormatNodeRule;
use ruff_formatter::write;
use rustpython_parser::ast::Arg;
use rustpython_ast::Arg;
#[derive(Default)]
pub struct FormatArg;

View file

@ -1,5 +1,5 @@
use ruff_formatter::write;
use rustpython_parser::ast::ArgWithDefault;
use rustpython_ast::ArgWithDefault;
use crate::prelude::*;
use crate::FormatNodeRule;

View file

@ -1,7 +1,7 @@
use std::usize;
use ruff_text_size::{TextRange, TextSize};
use rustpython_parser::ast::{Arguments, Ranged};
use rustpython_ast::{Arguments, Ranged};
use ruff_formatter::{format_args, write, FormatRuleWithOptions};
use ruff_python_ast::node::{AnyNodeRef, AstNode};

View file

@ -4,7 +4,7 @@ use crate::prelude::*;
use crate::AsFormat;
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::{format_args, write, Buffer, FormatResult};
use rustpython_parser::ast::{Comprehension, Expr, Ranged};
use rustpython_ast::{Comprehension, Expr, Ranged};
#[derive(Default)]
pub struct FormatComprehension;

View file

@ -3,7 +3,7 @@ use crate::expression::parentheses::Parenthesize;
use crate::prelude::*;
use crate::FormatNodeRule;
use ruff_formatter::write;
use rustpython_parser::ast::Decorator;
use rustpython_ast::Decorator;
#[derive(Default)]
pub struct FormatDecorator;

View file

@ -1,7 +1,7 @@
use crate::statement::stmt_if::format_elif_else_clause;
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::FormatResult;
use rustpython_parser::ast::ElifElseClause;
use rustpython_ast::ElifElseClause;
/// Note that this implementation misses the leading newlines before the leading comments because
/// it does not have access to the last node of the previous branch. The `StmtIf` therefore doesn't

View file

@ -6,7 +6,7 @@ use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::FormatRuleWithOptions;
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::node::AstNode;
use rustpython_parser::ast::ExceptHandlerExceptHandler;
use rustpython_ast::ExceptHandlerExceptHandler;
#[derive(Copy, Clone, Default)]
pub enum ExceptHandlerKind {

View file

@ -1,7 +1,7 @@
use crate::prelude::*;
use crate::AsFormat;
use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule};
use rustpython_parser::ast::{Identifier, Ranged};
use rustpython_ast::{Identifier, Ranged};
pub struct FormatIdentifier;

View file

@ -1,7 +1,7 @@
use crate::prelude::*;
use crate::FormatNodeRule;
use ruff_formatter::write;
use rustpython_parser::ast::Keyword;
use rustpython_ast::Keyword;
#[derive(Default)]
pub struct FormatKeyword;

View file

@ -1,6 +1,6 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::MatchCase;
use rustpython_ast::MatchCase;
#[derive(Default)]
pub struct FormatMatchCase;

View file

@ -1,6 +1,6 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::TypeIgnoreTypeIgnore;
use rustpython_ast::TypeIgnoreTypeIgnore;
#[derive(Default)]
pub struct FormatTypeIgnoreTypeIgnore;

View file

@ -1,4 +1,4 @@
use rustpython_parser::ast::WithItem;
use rustpython_ast::WithItem;
use ruff_formatter::{write, Buffer, FormatResult};

View file

@ -1,6 +1,6 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::PatternMatchAs;
use rustpython_ast::PatternMatchAs;
#[derive(Default)]
pub struct FormatPatternMatchAs;

View file

@ -1,6 +1,6 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::PatternMatchClass;
use rustpython_ast::PatternMatchClass;
#[derive(Default)]
pub struct FormatPatternMatchClass;

View file

@ -1,6 +1,6 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::PatternMatchMapping;
use rustpython_ast::PatternMatchMapping;
#[derive(Default)]
pub struct FormatPatternMatchMapping;

View file

@ -1,6 +1,6 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::PatternMatchOr;
use rustpython_ast::PatternMatchOr;
#[derive(Default)]
pub struct FormatPatternMatchOr;

View file

@ -1,6 +1,6 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::PatternMatchSequence;
use rustpython_ast::PatternMatchSequence;
#[derive(Default)]
pub struct FormatPatternMatchSequence;

View file

@ -1,6 +1,6 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::PatternMatchSingleton;
use rustpython_ast::PatternMatchSingleton;
#[derive(Default)]
pub struct FormatPatternMatchSingleton;

View file

@ -1,6 +1,6 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::PatternMatchStar;
use rustpython_ast::PatternMatchStar;
#[derive(Default)]
pub struct FormatPatternMatchStar;

View file

@ -1,4 +1,4 @@
use rustpython_parser::ast::PatternMatchValue;
use rustpython_ast::PatternMatchValue;
use ruff_formatter::{write, Buffer, FormatResult};

View file

@ -1,6 +1,6 @@
use crate::prelude::*;
use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule};
use rustpython_parser::ast::Stmt;
use rustpython_ast::Stmt;
pub(crate) mod stmt_ann_assign;
pub(crate) mod stmt_assert;

View file

@ -3,7 +3,7 @@ use crate::expression::parentheses::Parenthesize;
use crate::prelude::*;
use crate::FormatNodeRule;
use ruff_formatter::write;
use rustpython_parser::ast::StmtAnnAssign;
use rustpython_ast::StmtAnnAssign;
#[derive(Default)]
pub struct FormatStmtAnnAssign;

View file

@ -3,7 +3,7 @@ use crate::expression::parentheses::Parenthesize;
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::{space, text};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::StmtAssert;
use rustpython_ast::StmtAssert;
#[derive(Default)]
pub struct FormatStmtAssert;

View file

@ -1,4 +1,4 @@
use rustpython_parser::ast::{Expr, StmtAssign};
use rustpython_ast::{Expr, StmtAssign};
use ruff_formatter::{format_args, write, FormatError};

View file

@ -2,7 +2,7 @@ use crate::prelude::*;
use crate::statement::stmt_for::AnyStatementFor;
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::FormatResult;
use rustpython_parser::ast::StmtAsyncFor;
use rustpython_ast::StmtAsyncFor;
#[derive(Default)]
pub struct FormatStmtAsyncFor;

View file

@ -1,4 +1,4 @@
use rustpython_parser::ast::StmtAsyncFunctionDef;
use rustpython_ast::StmtAsyncFunctionDef;
use ruff_python_ast::function::AnyFunctionDefinition;

View file

@ -1,7 +1,7 @@
use crate::prelude::*;
use crate::statement::stmt_with::AnyStatementWith;
use crate::FormatNodeRule;
use rustpython_parser::ast::StmtAsyncWith;
use rustpython_ast::StmtAsyncWith;
#[derive(Default)]
pub struct FormatStmtAsyncWith;

View file

@ -3,7 +3,7 @@ use crate::expression::parentheses::Parenthesize;
use crate::{AsFormat, FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::{space, text};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::StmtAugAssign;
use rustpython_ast::StmtAugAssign;
#[derive(Default)]
pub struct FormatStmtAugAssign;

View file

@ -1,7 +1,7 @@
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::text;
use ruff_formatter::{Format, FormatResult};
use rustpython_parser::ast::StmtBreak;
use rustpython_ast::StmtBreak;
#[derive(Default)]
pub struct FormatStmtBreak;

View file

@ -1,5 +1,5 @@
use ruff_text_size::TextRange;
use rustpython_parser::ast::{Ranged, StmtClassDef};
use rustpython_ast::{Ranged, StmtClassDef};
use ruff_formatter::write;
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};

View file

@ -1,7 +1,7 @@
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::text;
use ruff_formatter::{Format, FormatResult};
use rustpython_parser::ast::StmtContinue;
use rustpython_ast::StmtContinue;
#[derive(Default)]
pub struct FormatStmtContinue;

View file

@ -5,7 +5,7 @@ use crate::expression::parentheses::Parenthesize;
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::{block_indent, format_with, space, text};
use ruff_formatter::{write, Buffer, Format, FormatResult};
use rustpython_parser::ast::{Ranged, StmtDelete};
use rustpython_ast::{Ranged, StmtDelete};
#[derive(Default)]
pub struct FormatStmtDelete;

View file

@ -1,5 +1,5 @@
use rustpython_ast::{Expr, Operator, StmtExpr};
use rustpython_parser::ast;
use rustpython_parser::ast::{Expr, Operator, StmtExpr};
use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::Parenthesize;

View file

@ -7,7 +7,7 @@ use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::{format_args, write, Buffer, FormatResult};
use ruff_python_ast::node::AnyNodeRef;
use ruff_text_size::TextRange;
use rustpython_parser::ast::{Expr, Ranged, Stmt, StmtAsyncFor, StmtFor, Suite};
use rustpython_ast::{Expr, Ranged, Stmt, StmtAsyncFor, StmtFor, Suite};
#[derive(Debug)]
struct ExprTupleWithoutParentheses<'a>(&'a Expr);

View file

@ -1,4 +1,4 @@
use rustpython_parser::ast::{Ranged, StmtFunctionDef};
use rustpython_ast::{Ranged, StmtFunctionDef};
use ruff_formatter::{write, FormatOwnedWithRule, FormatRefWithRule};
use ruff_python_ast::function::AnyFunctionDefinition;

View file

@ -1,6 +1,6 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::StmtGlobal;
use rustpython_ast::StmtGlobal;
#[derive(Default)]
pub struct FormatStmtGlobal;

View file

@ -5,7 +5,7 @@ use crate::prelude::*;
use crate::FormatNodeRule;
use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef;
use rustpython_parser::ast::{ElifElseClause, StmtIf};
use rustpython_ast::{ElifElseClause, StmtIf};
#[derive(Default)]
pub struct FormatStmtIf;

View file

@ -1,7 +1,7 @@
use crate::{FormatNodeRule, FormattedIterExt, PyFormatter};
use ruff_formatter::prelude::{format_args, format_with, space, text};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::StmtImport;
use rustpython_ast::StmtImport;
#[derive(Default)]
pub struct FormatStmtImport;

View file

@ -2,7 +2,7 @@ use crate::builders::{parenthesize_if_expands, PyFormatterExtensions};
use crate::{AsFormat, FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::{dynamic_text, format_with, space, text};
use ruff_formatter::{write, Buffer, Format, FormatResult};
use rustpython_parser::ast::{Ranged, StmtImportFrom};
use rustpython_ast::{Ranged, StmtImportFrom};
#[derive(Default)]
pub struct FormatStmtImportFrom;

View file

@ -1,6 +1,6 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::StmtMatch;
use rustpython_ast::StmtMatch;
#[derive(Default)]
pub struct FormatStmtMatch;

View file

@ -1,6 +1,6 @@
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::StmtNonlocal;
use rustpython_ast::StmtNonlocal;
#[derive(Default)]
pub struct FormatStmtNonlocal;

View file

@ -1,7 +1,7 @@
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::text;
use ruff_formatter::{Format, FormatResult};
use rustpython_parser::ast::StmtPass;
use rustpython_ast::StmtPass;
#[derive(Default)]
pub struct FormatStmtPass;

View file

@ -4,7 +4,7 @@ use ruff_formatter::prelude::{space, text};
use ruff_formatter::{write, Buffer, Format, FormatResult};
use crate::expression::maybe_parenthesize_expression;
use rustpython_parser::ast::StmtRaise;
use rustpython_ast::StmtRaise;
#[derive(Default)]
pub struct FormatStmtRaise;

View file

@ -3,7 +3,7 @@ use crate::expression::parentheses::Parenthesize;
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::{space, text};
use ruff_formatter::{write, Buffer, Format, FormatResult};
use rustpython_parser::ast::StmtReturn;
use rustpython_ast::StmtReturn;
#[derive(Default)]
pub struct FormatStmtReturn;

View file

@ -10,7 +10,7 @@ use ruff_formatter::FormatRuleWithOptions;
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::node::AnyNodeRef;
use ruff_text_size::TextRange;
use rustpython_parser::ast::{ExceptHandler, Ranged, StmtTry, StmtTryStar, Suite};
use rustpython_ast::{ExceptHandler, Ranged, StmtTry, StmtTryStar, Suite};
pub(super) enum AnyStatementTry<'a> {
Try(&'a StmtTry),

View file

@ -2,7 +2,7 @@ use crate::statement::stmt_try::AnyStatementTry;
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::Format;
use ruff_formatter::FormatResult;
use rustpython_parser::ast::StmtTryStar;
use rustpython_ast::StmtTryStar;
#[derive(Default)]
pub struct FormatStmtTryStar;

View file

@ -1,6 +1,6 @@
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::StmtTypeAlias;
use rustpython_ast::StmtTypeAlias;
#[derive(Default)]
pub struct FormatStmtTypeAlias;

View file

@ -5,7 +5,7 @@ use crate::prelude::*;
use crate::FormatNodeRule;
use ruff_formatter::write;
use ruff_python_ast::node::AstNode;
use rustpython_parser::ast::{Ranged, Stmt, StmtWhile};
use rustpython_ast::{Ranged, Stmt, StmtWhile};
#[derive(Default)]
pub struct FormatStmtWhile;

View file

@ -1,5 +1,5 @@
use ruff_text_size::TextRange;
use rustpython_parser::ast::{Ranged, StmtAsyncWith, StmtWith, Suite, WithItem};
use rustpython_ast::{Ranged, StmtAsyncWith, StmtWith, Suite, WithItem};
use ruff_formatter::{format_args, write, FormatError};
use ruff_python_ast::node::AnyNodeRef;

View file

@ -1,4 +1,4 @@
use rustpython_parser::ast::{Ranged, Stmt, Suite};
use rustpython_ast::{Ranged, Stmt, Suite};
use ruff_formatter::{
format_args, write, FormatOwnedWithRule, FormatRefWithRule, FormatRuleWithOptions,
@ -170,7 +170,7 @@ impl<'ast> IntoFormat<PyFormatContext<'ast>> for Suite {
#[cfg(test)]
mod tests {
use rustpython_parser::ast::Suite;
use rustpython_ast::Suite;
use rustpython_parser::Parse;
use ruff_formatter::format;