Use the formatter prelude in more files (#6882)

Removes a bunch of imports that are made redundant by the prelude.
This commit is contained in:
Charlie Marsh 2023-08-25 16:51:07 -04:00 committed by GitHub
parent 91a780c771
commit edb9b0c62a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
81 changed files with 139 additions and 230 deletions

View file

@ -89,9 +89,10 @@ for group, group_nodes in nodes_grouped.items():
continue
code = f"""
use crate::{{verbatim_text, FormatNodeRule, PyFormatter}};
use ruff_formatter::{{write, Buffer, FormatResult}};
use ruff_formatter::write;
use ruff_python_ast::{node};
use crate::verbatim_text;
use crate::prelude::*;
#[derive(Default)]
pub struct Format{node};

View file

@ -10,7 +10,6 @@ use crate::expression::parentheses::{
};
use crate::expression::CallChainLayout;
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatExprAttribute {

View file

@ -1,12 +1,10 @@
use ruff_python_ast::ExprAwait;
use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::ExprAwait;
use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses, Parenthesize};
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatExprAwait;

View file

@ -18,7 +18,6 @@ use crate::expression::parentheses::{
};
use crate::expression::string::StringLayout;
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatExprBinOp;

View file

@ -6,7 +6,6 @@ use crate::comments::{dangling_comments, SourceComment};
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::expression::CallChainLayout;
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatExprCall {

View file

@ -1,13 +1,13 @@
use ruff_formatter::{write, FormatOwnedWithRule, FormatRefWithRule};
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::{CmpOp, ExprCompare};
use crate::comments::{leading_comments, SourceComment};
use crate::expression::parentheses::{
in_parentheses_only_group, in_parentheses_only_soft_line_break_or_space, NeedsParentheses,
OptionalParentheses,
};
use crate::prelude::*;
use crate::FormatNodeRule;
use ruff_formatter::{write, FormatOwnedWithRule, FormatRefWithRule};
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::{CmpOp, ExprCompare};
#[derive(Default)]
pub struct FormatExprCompare;

View file

@ -1,16 +1,15 @@
use crate::comments::SourceComment;
use ruff_formatter::FormatRuleWithOptions;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::{Constant, ExprConstant, Ranged};
use ruff_text_size::{TextLen, TextRange};
use crate::comments::SourceComment;
use crate::expression::number::{FormatComplex, FormatFloat, FormatInt};
use crate::expression::parentheses::{should_use_best_fit, NeedsParentheses, OptionalParentheses};
use crate::expression::string::{
AnyString, FormatString, StringLayout, StringPrefix, StringQuotes,
};
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatExprConstant {

View file

@ -9,7 +9,6 @@ use crate::expression::parentheses::{
empty_parenthesized, parenthesized, NeedsParentheses, OptionalParentheses,
};
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatExprDict;

View file

@ -1,14 +1,12 @@
use ruff_formatter::prelude::{
format_args, format_with, group, soft_line_break_or_space, space, text,
};
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::ExprDictComp;
use crate::context::PyFormatContext;
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
use crate::AsFormat;
use crate::{FormatNodeRule, FormattedIterExt, PyFormatter};
use crate::prelude::*;
#[derive(Default)]
pub struct FormatExprDictComp;

View file

@ -1,14 +1,14 @@
use super::string::{AnyString, FormatString};
use crate::context::PyFormatContext;
use memchr::memchr2;
use crate::expression::parentheses::{should_use_best_fit, NeedsParentheses, OptionalParentheses};
use crate::prelude::*;
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::FormatResult;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::ExprFString;
use crate::expression::parentheses::{should_use_best_fit, NeedsParentheses, OptionalParentheses};
use crate::prelude::*;
use super::string::{AnyString, FormatString};
#[derive(Default)]
pub struct FormatExprFString;

View file

@ -1,10 +1,9 @@
use crate::context::PyFormatContext;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::FormatResult;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::ExprFormattedValue;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::prelude::*;
#[derive(Default)]
pub struct FormatExprFormattedValue;

View file

@ -3,11 +3,9 @@ use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::ExprGeneratorExp;
use crate::comments::SourceComment;
use crate::context::PyFormatContext;
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
use crate::prelude::*;
use crate::AsFormat;
use crate::{FormatNodeRule, PyFormatter};
#[derive(Eq, PartialEq, Debug, Default)]
pub enum GeneratorExpParentheses {

View file

@ -1,13 +1,13 @@
use ruff_formatter::{format_args, write};
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::ExprIfExp;
use crate::comments::leading_comments;
use crate::expression::parentheses::{
in_parentheses_only_group, in_parentheses_only_soft_line_break_or_space, NeedsParentheses,
OptionalParentheses,
};
use crate::prelude::*;
use crate::FormatNodeRule;
use ruff_formatter::{format_args, write};
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::ExprIfExp;
#[derive(Default)]
pub struct FormatExprIfExp;

View file

@ -1,6 +1,7 @@
use crate::prelude::*;
use ruff_python_ast::{ExprIpyEscapeCommand, Ranged};
use crate::prelude::*;
#[derive(Default)]
pub struct FormatExprIpyEscapeCommand;

View file

@ -1,14 +1,11 @@
use ruff_formatter::prelude::{space, text};
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::ExprLambda;
use crate::comments::{dangling_comments, SourceComment};
use crate::context::PyFormatContext;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::other::parameters::ParametersParentheses;
use crate::AsFormat;
use crate::{FormatNodeRule, PyFormatter};
use crate::prelude::*;
#[derive(Default)]
pub struct FormatExprLambda;

View file

@ -1,13 +1,12 @@
use crate::comments::SourceComment;
use ruff_formatter::prelude::format_with;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::{ExprList, Ranged};
use crate::comments::SourceComment;
use crate::expression::parentheses::{
empty_parenthesized, parenthesized, NeedsParentheses, OptionalParentheses,
};
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatExprList;

View file

@ -3,11 +3,9 @@ use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::ExprListComp;
use crate::comments::SourceComment;
use crate::context::PyFormatContext;
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
use crate::prelude::*;
use crate::AsFormat;
use crate::{FormatNodeRule, PyFormatter};
#[derive(Default)]
pub struct FormatExprListComp;

View file

@ -1,11 +1,11 @@
use crate::comments::SourceComment;
use crate::expression::parentheses::{should_use_best_fit, NeedsParentheses, OptionalParentheses};
use crate::prelude::*;
use crate::FormatNodeRule;
use ruff_formatter::{write, FormatContext};
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::ExprName;
use crate::comments::SourceComment;
use crate::expression::parentheses::{should_use_best_fit, NeedsParentheses, OptionalParentheses};
use crate::prelude::*;
#[derive(Default)]
pub struct FormatExprName;

View file

@ -1,14 +1,11 @@
use crate::comments::{dangling_comments, SourceComment};
use crate::context::PyFormatContext;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::{AsFormat, FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::{
format_args, group, hard_line_break, soft_line_break_or_space, space, text,
};
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_formatter::{format_args, write};
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::ExprNamedExpr;
use crate::comments::{dangling_comments, SourceComment};
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::prelude::*;
#[derive(Default)]
pub struct FormatExprNamedExpr;

View file

@ -1,10 +1,9 @@
use crate::comments::SourceComment;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::{ExprSet, Ranged};
use crate::comments::SourceComment;
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatExprSet;

View file

@ -3,11 +3,9 @@ use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::ExprSetComp;
use crate::comments::SourceComment;
use crate::context::PyFormatContext;
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
use crate::prelude::*;
use crate::AsFormat;
use crate::{FormatNodeRule, PyFormatter};
#[derive(Default)]
pub struct FormatExprSetComp;

View file

@ -1,15 +1,12 @@
use ruff_formatter::{write, FormatError};
use ruff_python_ast::node::{AnyNodeRef, AstNode};
use ruff_python_ast::{Expr, ExprSlice, ExprUnaryOp, UnaryOp};
use ruff_python_trivia::{SimpleToken, SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::TextRange;
use ruff_formatter::prelude::{hard_line_break, line_suffix_boundary, space, text};
use ruff_formatter::{write, Buffer, Format, FormatError, FormatResult};
use ruff_python_ast::node::{AnyNodeRef, AstNode};
use ruff_python_trivia::{SimpleToken, SimpleTokenKind, SimpleTokenizer};
use crate::comments::{dangling_comments, SourceComment};
use crate::context::PyFormatContext;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::{AsFormat, FormatNodeRule, PyFormatter};
use crate::prelude::*;
#[derive(Default)]
pub struct FormatExprSlice;

View file

@ -1,13 +1,11 @@
use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::ExprStarred;
use crate::comments::{dangling_comments, SourceComment};
use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef;
use crate::context::PyFormatContext;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatExprStarred;

View file

@ -3,13 +3,12 @@ use ruff_python_ast::node::{AnyNodeRef, AstNode};
use ruff_python_ast::{Expr, ExprSubscript};
use crate::comments::{trailing_comments, SourceComment};
use crate::context::PyFormatContext;
use crate::context::{NodeLevel, WithNodeLevel};
use crate::expression::expr_tuple::TupleParentheses;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::expression::CallChainLayout;
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatExprSubscript {

View file

@ -1,16 +1,12 @@
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::UnaryOp;
use ruff_python_ast::{ExprUnaryOp, Ranged};
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::{TextLen, TextRange};
use ruff_formatter::prelude::{hard_line_break, space, text};
use ruff_formatter::{Format, FormatResult};
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};
use crate::comments::trailing_comments;
use crate::context::PyFormatContext;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::{AsFormat, FormatNodeRule, PyFormatter};
use crate::prelude::*;
#[derive(Default)]
pub struct FormatExprUnaryOp;

View file

@ -1,13 +1,12 @@
use crate::context::PyFormatContext;
use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses, Parenthesize};
use crate::prelude::*;
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::{Expr, ExprYield, ExprYieldFrom, Ranged};
use ruff_text_size::TextRange;
use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses, Parenthesize};
use crate::prelude::*;
pub(super) enum AnyExpressionYield<'a> {
Yield(&'a ExprYield),
YieldFrom(&'a ExprYieldFrom),

View file

@ -1,11 +1,10 @@
use crate::expression::expr_yield::AnyExpressionYield;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::prelude::PyFormatContext;
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::{Format, FormatResult};
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::ExprYieldFrom;
use crate::expression::expr_yield::AnyExpressionYield;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::prelude::*;
#[derive(Default)]
pub struct FormatExprYieldFrom;

View file

@ -1,6 +1,7 @@
use itertools::Itertools;
use std::cmp::Ordering;
use itertools::Itertools;
use ruff_formatter::{
format_args, write, FormatOwnedWithRule, FormatRefWithRule, FormatRule, FormatRuleWithOptions,
};

View file

@ -1,8 +1,8 @@
use crate::context::PyFormatContext;
use crate::{AsFormat, IntoFormat, PyFormatter};
use ruff_formatter::{Format, FormatOwnedWithRule, FormatRefWithRule, FormatResult, FormatRule};
use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule};
use ruff_python_ast::Mod;
use crate::prelude::*;
pub(crate) mod mod_expression;
pub(crate) mod mod_module;

View file

@ -1,7 +1,7 @@
use crate::{AsFormat, FormatNodeRule, PyFormatter};
use ruff_formatter::{Format, FormatResult};
use ruff_python_ast::ModExpression;
use crate::prelude::*;
#[derive(Default)]
pub struct FormatModExpression;

View file

@ -1,9 +1,10 @@
use crate::statement::suite::SuiteKind;
use crate::{AsFormat, FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::hard_line_break;
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_formatter::write;
use ruff_python_ast::ModModule;
use crate::prelude::*;
use crate::statement::suite::SuiteKind;
#[derive(Default)]
pub struct FormatModModule;

View file

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

View file

@ -1,14 +1,13 @@
use crate::comments::SourceComment;
use ruff_formatter::write;
use ruff_python_ast::node::AstNode;
use ruff_python_ast::{Arguments, Expr, Ranged};
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::{TextRange, TextSize};
use crate::comments::SourceComment;
use crate::expression::expr_generator_exp::GeneratorExpParentheses;
use crate::expression::parentheses::{empty_parenthesized, parenthesized, Parentheses};
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatArguments;

View file

@ -1,10 +1,9 @@
use ruff_formatter::{format_args, write, Buffer, FormatResult};
use ruff_python_ast::{Comprehension, Expr, Ranged};
use crate::comments::{leading_comments, trailing_comments, SourceComment};
use crate::expression::expr_tuple::TupleParentheses;
use crate::prelude::*;
use crate::AsFormat;
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::{format_args, write, Buffer, FormatResult};
use ruff_python_ast::{Comprehension, Expr, Ranged};
#[derive(Default)]
pub struct FormatComprehension;

View file

@ -1,10 +1,10 @@
use ruff_formatter::write;
use ruff_python_ast::Decorator;
use crate::comments::{SourceComment, SuppressionKind};
use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::Parenthesize;
use crate::prelude::*;
use crate::FormatNodeRule;
use ruff_formatter::write;
use ruff_python_ast::Decorator;
#[derive(Default)]
pub struct FormatDecorator;

View file

@ -1,8 +1,8 @@
use crate::statement::stmt_if::format_elif_else_clause;
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::FormatResult;
use ruff_python_ast::ElifElseClause;
use crate::prelude::*;
use crate::statement::stmt_if::format_elif_else_clause;
/// 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
/// call this but `format_elif_else_clause` directly.

View file

@ -1,5 +1,5 @@
use ruff_formatter::write;
use ruff_formatter::FormatRuleWithOptions;
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::ExceptHandlerExceptHandler;
use crate::comments::SourceComment;
@ -7,7 +7,6 @@ use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::Parenthesize;
use crate::prelude::*;
use crate::statement::clause::{clause_body, clause_header, ClauseHeader};
use crate::{FormatNodeRule, PyFormatter};
#[derive(Copy, Clone, Default)]
pub enum ExceptHandlerKind {

View file

@ -1,5 +1,5 @@
use crate::prelude::*;
use crate::AsFormat;
use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule};
use ruff_python_ast::{Identifier, Ranged};

View file

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

View file

@ -1,4 +1,4 @@
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_formatter::write;
use ruff_python_ast::node::AstNode;
use ruff_python_ast::MatchCase;
@ -7,7 +7,6 @@ use crate::comments::SourceComment;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses, Parentheses};
use crate::prelude::*;
use crate::statement::clause::{clause_body, clause_header, ClauseHeader};
use crate::{FormatNodeRule, PyFormatter};
#[derive(Default)]
pub struct FormatMatchCase;

View file

@ -1,8 +1,8 @@
use crate::prelude::*;
use crate::FormatNodeRule;
use ruff_formatter::write;
use ruff_python_ast::Parameter;
use crate::prelude::*;
#[derive(Default)]
pub struct FormatParameter;

View file

@ -2,7 +2,6 @@ use ruff_formatter::write;
use ruff_python_ast::ParameterWithDefault;
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatParameterWithDefault;

View file

@ -13,7 +13,6 @@ use crate::comments::{
use crate::context::{NodeLevel, WithNodeLevel};
use crate::expression::parentheses::empty_parenthesized;
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
pub enum ParametersParentheses {

View file

@ -1,11 +1,10 @@
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_formatter::write;
use ruff_python_ast::WithItem;
use crate::comments::SourceComment;
use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::{parenthesized, Parentheses, Parenthesize};
use crate::prelude::*;
use crate::{FormatNodeRule, PyFormatter};
#[derive(Default)]
pub struct FormatWithItem;

View file

@ -1,11 +1,10 @@
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::PatternMatchAs;
use crate::comments::{dangling_comments, SourceComment};
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::prelude::*;
use crate::{FormatNodeRule, PyFormatter};
#[derive(Default)]
pub struct FormatPatternMatchAs;

View file

@ -1,10 +1,10 @@
use crate::comments::{dangling_comments, SourceComment};
use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::{Pattern, PatternMatchClass, Ranged};
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::{TextRange, TextSize};
use crate::comments::{dangling_comments, SourceComment};
use crate::expression::parentheses::{
empty_parenthesized, parenthesized, NeedsParentheses, OptionalParentheses, Parentheses,
};

View file

@ -1,10 +1,10 @@
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::PatternMatchOr;
use crate::context::PyFormatContext;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
use crate::not_yet_implemented_custom_text;
use crate::prelude::*;
#[derive(Default)]
pub struct FormatPatternMatchOr;

View file

@ -1,16 +1,13 @@
use ruff_formatter::prelude::format_with;
use ruff_formatter::{Format, FormatResult};
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::{PatternMatchSequence, Ranged};
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::TextRange;
use crate::builders::PyFormatterExtensions;
use crate::context::PyFormatContext;
use crate::expression::parentheses::{
empty_parenthesized, optional_parentheses, parenthesized, NeedsParentheses, OptionalParentheses,
};
use crate::{FormatNodeRule, PyFormatter};
use crate::prelude::*;
#[derive(Default)]
pub struct FormatPatternMatchSequence;

View file

@ -1,9 +1,8 @@
use crate::prelude::*;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::{Constant, PatternMatchSingleton};
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
use crate::{FormatNodeRule, PyFormatter};
use crate::prelude::*;
#[derive(Default)]
pub struct FormatPatternMatchSingleton;

View file

@ -1,4 +1,4 @@
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::PatternMatchStar;

View file

@ -3,7 +3,6 @@ use ruff_python_ast::PatternMatchValue;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses, Parentheses};
use crate::prelude::*;
use crate::{AsFormat, FormatNodeRule, PyFormatter};
#[derive(Default)]
pub struct FormatPatternMatchValue;

View file

@ -1,9 +1,3 @@
use crate::comments::{
leading_alternate_branch_comments, trailing_comments, SourceComment, SuppressionKind,
};
use crate::prelude::*;
use crate::statement::suite::{contains_only_an_ellipsis, SuiteKind};
use crate::verbatim::write_suppressed_clause_header;
use ruff_formatter::{write, Argument, Arguments, FormatError};
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::{
@ -13,6 +7,13 @@ use ruff_python_ast::{
use ruff_python_trivia::{SimpleToken, SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::{TextRange, TextSize};
use crate::comments::{
leading_alternate_branch_comments, trailing_comments, SourceComment, SuppressionKind,
};
use crate::prelude::*;
use crate::statement::suite::{contains_only_an_ellipsis, SuiteKind};
use crate::verbatim::write_suppressed_clause_header;
/// The header of a compound statement clause.
///
/// > A compound statement consists of one or more clauses. A clause consists of a header and a suite.

View file

@ -1,10 +1,10 @@
use ruff_formatter::write;
use ruff_python_ast::StmtAnnAssign;
use crate::comments::{SourceComment, SuppressionKind};
use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::Parenthesize;
use crate::prelude::*;
use crate::FormatNodeRule;
use ruff_formatter::write;
use ruff_python_ast::StmtAnnAssign;
#[derive(Default)]
pub struct FormatStmtAnnAssign;

View file

@ -1,11 +1,12 @@
use ruff_formatter::prelude::{space, text};
use ruff_formatter::write;
use ruff_python_ast::StmtAssert;
use crate::comments::{SourceComment, SuppressionKind};
use crate::context::PyFormatContext;
use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::Parenthesize;
use crate::{FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::{space, text};
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_python_ast::StmtAssert;
use crate::prelude::*;
#[derive(Default)]
pub struct FormatStmtAssert;

View file

@ -1,12 +1,11 @@
use crate::comments::{SourceComment, SuppressionKind};
use ruff_formatter::{format_args, write, FormatError};
use ruff_python_ast::{Expr, StmtAssign};
use crate::comments::{SourceComment, SuppressionKind};
use crate::context::{NodeLevel, WithNodeLevel};
use crate::expression::parentheses::{Parentheses, Parenthesize};
use crate::expression::{has_own_parentheses, maybe_parenthesize_expression};
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatStmtAssign;

View file

@ -2,7 +2,6 @@ use ruff_python_ast::StmtBreak;
use crate::comments::{SourceComment, SuppressionKind};
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatStmtBreak;

View file

@ -4,10 +4,8 @@ use ruff_python_trivia::lines_after_ignoring_trivia;
use crate::comments::{leading_comments, trailing_comments, SourceComment};
use crate::prelude::*;
use crate::statement::suite::SuiteKind;
use crate::statement::clause::{clause_body, clause_header, ClauseHeader};
use crate::FormatNodeRule;
use crate::statement::suite::SuiteKind;
#[derive(Default)]
pub struct FormatStmtClassDef;

View file

@ -1,8 +1,7 @@
use crate::comments::{SourceComment, SuppressionKind};
use ruff_python_ast::StmtContinue;
use crate::comments::{SourceComment, SuppressionKind};
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatStmtContinue;

View file

@ -6,7 +6,6 @@ use crate::comments::{dangling_node_comments, SourceComment, SuppressionKind};
use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::Parenthesize;
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatStmtDelete;

View file

@ -1,11 +1,10 @@
use crate::comments::{SourceComment, SuppressionKind};
use ruff_python_ast as ast;
use ruff_python_ast::{Expr, Operator, StmtExpr};
use crate::comments::{SourceComment, SuppressionKind};
use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::Parenthesize;
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatStmtExpr;

View file

@ -7,7 +7,6 @@ use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::Parenthesize;
use crate::prelude::*;
use crate::statement::clause::{clause_body, clause_header, ClauseHeader, ElseClause};
use crate::FormatNodeRule;
#[derive(Debug)]
struct ExprTupleWithoutParentheses<'a>(&'a Expr);

View file

@ -9,7 +9,6 @@ use crate::prelude::*;
use crate::statement::clause::{clause_body, clause_header, ClauseHeader};
use crate::statement::stmt_class_def::FormatDecorators;
use crate::statement::suite::SuiteKind;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatStmtFunctionDef;

View file

@ -1,10 +1,9 @@
use crate::comments::{SourceComment, SuppressionKind};
use ruff_formatter::{format_args, write};
use ruff_python_ast::node::AstNode;
use ruff_python_ast::StmtGlobal;
use crate::comments::{SourceComment, SuppressionKind};
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatStmtGlobal;

View file

@ -7,7 +7,6 @@ use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::Parenthesize;
use crate::prelude::*;
use crate::statement::clause::{clause_body, clause_header, ClauseHeader};
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatStmtIf;

View file

@ -1,9 +1,8 @@
use crate::prelude::*;
use ruff_formatter::{format_args, write};
use ruff_python_ast::StmtImport;
use crate::comments::{SourceComment, SuppressionKind};
use crate::FormatNodeRule;
use crate::prelude::*;
#[derive(Default)]
pub struct FormatStmtImport;

View file

@ -6,7 +6,6 @@ use crate::builders::{parenthesize_if_expands, PyFormatterExtensions, TrailingCo
use crate::comments::{SourceComment, SuppressionKind};
use crate::expression::parentheses::parenthesized;
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatStmtImportFrom;

View file

@ -1,6 +1,7 @@
use ruff_python_ast::{Ranged, StmtIpyEscapeCommand};
use crate::comments::{SourceComment, SuppressionKind};
use crate::prelude::*;
use ruff_python_ast::{Ranged, StmtIpyEscapeCommand};
#[derive(Default)]
pub struct FormatStmtIpyEscapeCommand;

View file

@ -7,7 +7,6 @@ use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::Parenthesize;
use crate::prelude::*;
use crate::statement::clause::{clause_header, ClauseHeader};
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatStmtMatch;

View file

@ -1,10 +1,9 @@
use crate::comments::{SourceComment, SuppressionKind};
use ruff_formatter::{format_args, write};
use ruff_python_ast::node::AstNode;
use ruff_python_ast::StmtNonlocal;
use crate::comments::{SourceComment, SuppressionKind};
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatStmtNonlocal;

View file

@ -1,8 +1,7 @@
use crate::comments::{SourceComment, SuppressionKind};
use ruff_python_ast::StmtPass;
use crate::comments::{SourceComment, SuppressionKind};
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatStmtPass;

View file

@ -1,11 +1,10 @@
use crate::comments::{SourceComment, SuppressionKind};
use ruff_formatter::write;
use ruff_python_ast::StmtRaise;
use crate::comments::{SourceComment, SuppressionKind};
use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::Parenthesize;
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatStmtRaise;

View file

@ -5,7 +5,6 @@ use crate::comments::{SourceComment, SuppressionKind};
use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::Parenthesize;
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatStmtReturn;

View file

@ -8,7 +8,6 @@ use crate::other::except_handler_except_handler::ExceptHandlerKind;
use crate::prelude::*;
use crate::statement::clause::{clause_body, clause_header, ClauseHeader, ElseClause};
use crate::statement::{FormatRefWithRule, Stmt};
use crate::{FormatNodeRule, PyFormatter};
#[derive(Default)]
pub struct FormatStmtTry;

View file

@ -1,11 +1,10 @@
use crate::comments::{SourceComment, SuppressionKind};
use ruff_formatter::write;
use ruff_python_ast::StmtTypeAlias;
use crate::comments::{SourceComment, SuppressionKind};
use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::Parenthesize;
use crate::prelude::*;
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatStmtTypeAlias;

View file

@ -7,7 +7,6 @@ use crate::expression::maybe_parenthesize_expression;
use crate::expression::parentheses::Parenthesize;
use crate::prelude::*;
use crate::statement::clause::{clause_body, clause_header, ClauseHeader, ElseClause};
use crate::FormatNodeRule;
#[derive(Default)]
pub struct FormatStmtWhile;

View file

@ -1,4 +1,3 @@
use crate::comments::{leading_comments, trailing_comments, Comments};
use ruff_formatter::{write, FormatOwnedWithRule, FormatRefWithRule, FormatRuleWithOptions};
use ruff_python_ast::helpers::is_compound_statement;
use ruff_python_ast::node::AnyNodeRef;
@ -6,6 +5,7 @@ use ruff_python_ast::{self as ast, Constant, Expr, ExprConstant, Ranged, Stmt, S
use ruff_python_trivia::{lines_after_ignoring_trivia, lines_before};
use ruff_text_size::TextRange;
use crate::comments::{leading_comments, trailing_comments, Comments};
use crate::context::{NodeLevel, WithNodeLevel};
use crate::expression::expr_constant::ExprConstantLayout;
use crate::expression::string::StringLayout;

View file

@ -1,7 +1,8 @@
use crate::prelude::*;
use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule};
use ruff_python_ast::TypeParam;
use crate::prelude::*;
pub(crate) mod type_param_param_spec;
pub(crate) mod type_param_type_var;
pub(crate) mod type_param_type_var_tuple;

View file

@ -1,29 +0,0 @@
use crate::builders::PyFormatterExtensions;
use crate::context::PyFormatContext;
use crate::expression::parentheses::parenthesized;
use crate::prelude::*;
use ruff_formatter::{Format, FormatResult};
use ruff_python_ast::TypeParam;
use ruff_text_size::TextSize;
pub(crate) struct FormatTypeParamsClause<'a> {
pub(crate) sequence_end: TextSize,
pub(crate) type_params: &'a Vec<TypeParam>,
}
/// Formats a sequence of [`TypeParam`] nodes.
impl Format<PyFormatContext<'_>> for FormatTypeParamsClause<'_> {
fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> {
if self.type_params.is_empty() {
return Ok(());
}
let items = format_with(|f| {
f.join_comma_separated(self.sequence_end)
.nodes(self.type_params.iter())
.finish()
});
parenthesized("[", &items, "]").fmt(f)
}
}

View file

@ -1,8 +1,8 @@
use crate::{AsFormat, FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::text;
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_formatter::write;
use ruff_python_ast::TypeParamParamSpec;
use crate::prelude::*;
#[derive(Default)]
pub struct FormatTypeParamParamSpec;

View file

@ -1,8 +1,8 @@
use crate::{AsFormat, FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::{space, text};
use ruff_formatter::{write, Buffer, Format, FormatResult};
use ruff_formatter::write;
use ruff_python_ast::TypeParamTypeVar;
use crate::prelude::*;
#[derive(Default)]
pub struct FormatTypeParamTypeVar;

View file

@ -1,8 +1,8 @@
use crate::{AsFormat, FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::text;
use ruff_formatter::{write, Buffer, FormatResult};
use ruff_formatter::write;
use ruff_python_ast::TypeParamTypeVarTuple;
use crate::prelude::*;
#[derive(Default)]
pub struct FormatTypeParamTypeVarTuple;