mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:39:12 +00:00
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:
parent
91a780c771
commit
edb9b0c62a
81 changed files with 139 additions and 230 deletions
|
@ -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};
|
||||
|
|
|
@ -10,7 +10,6 @@ use crate::expression::parentheses::{
|
|||
};
|
||||
use crate::expression::CallChainLayout;
|
||||
use crate::prelude::*;
|
||||
use crate::FormatNodeRule;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprAttribute {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -18,7 +18,6 @@ use crate::expression::parentheses::{
|
|||
};
|
||||
use crate::expression::string::StringLayout;
|
||||
use crate::prelude::*;
|
||||
use crate::FormatNodeRule;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprBinOp;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -9,7 +9,6 @@ use crate::expression::parentheses::{
|
|||
empty_parenthesized, parenthesized, NeedsParentheses, OptionalParentheses,
|
||||
};
|
||||
use crate::prelude::*;
|
||||
use crate::FormatNodeRule;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprDict;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::prelude::*;
|
||||
use ruff_python_ast::{ExprIpyEscapeCommand, Ranged};
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprIpyEscapeCommand;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use itertools::Itertools;
|
||||
use std::cmp::Ordering;
|
||||
|
||||
use itertools::Itertools;
|
||||
|
||||
use ruff_formatter::{
|
||||
format_args, write, FormatOwnedWithRule, FormatRefWithRule, FormatRule, FormatRuleWithOptions,
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::prelude::*;
|
||||
use crate::AsFormat;
|
||||
|
||||
use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule};
|
||||
use ruff_python_ast::{Identifier, Ranged};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ use ruff_formatter::write;
|
|||
use ruff_python_ast::ParameterWithDefault;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::FormatNodeRule;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatParameterWithDefault;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.’
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue