Move {AnyNodeRef, AstNode} to ruff_python_ast crate root (#8030)

This is a do-over of https://github.com/astral-sh/ruff/pull/8011, which
I accidentally merged into a non-`main` branch. Sorry!
This commit is contained in:
Charlie Marsh 2023-10-17 20:01:18 -04:00 committed by GitHub
parent d85950ce5a
commit d685107638
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
72 changed files with 76 additions and 75 deletions

View file

@ -3,7 +3,7 @@
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use ruff_diagnostics::Edit; use ruff_diagnostics::Edit;
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{self as ast, Arguments, ExceptHandler, Stmt}; use ruff_python_ast::{self as ast, Arguments, ExceptHandler, Stmt};
use ruff_python_codegen::Stylist; use ruff_python_codegen::Stylist;
use ruff_python_index::Indexer; use ruff_python_index::Indexer;

View file

@ -5,8 +5,8 @@ use rustc_hash::FxHashMap;
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
use ruff_macros::{derive_message_formats, violation}; use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::comparable::ComparableExpr;
use ruff_python_ast::node::AstNode;
use ruff_python_ast::parenthesize::parenthesized_range; use ruff_python_ast::parenthesize::parenthesized_range;
use ruff_python_ast::AstNode;
use ruff_python_ast::{self as ast, Arguments, Constant, Decorator, Expr, ExprContext}; use ruff_python_ast::{self as ast, Arguments, Constant, Decorator, Expr, ExprContext};
use ruff_python_codegen::Generator; use ruff_python_codegen::Generator;
use ruff_python_trivia::CommentRanges; use ruff_python_trivia::CommentRanges;

View file

@ -6,7 +6,7 @@ use log::error;
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
use ruff_macros::{derive_message_formats, violation}; use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{self as ast, whitespace, Constant, ElifElseClause, Expr, Stmt}; use ruff_python_ast::{self as ast, whitespace, Constant, ElifElseClause, Expr, Stmt};
use ruff_python_codegen::Stylist; use ruff_python_codegen::Stylist;
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};

View file

@ -1,8 +1,8 @@
use ruff_diagnostics::Edit; use ruff_diagnostics::Edit;
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
use ruff_macros::{derive_message_formats, violation}; use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::parenthesize::parenthesized_range; use ruff_python_ast::parenthesize::parenthesized_range;
use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{self as ast, Arguments, CmpOp, Comprehension, Expr}; use ruff_python_ast::{self as ast, Arguments, CmpOp, Comprehension, Expr};
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::{Ranged, TextRange}; use ruff_text_size::{Ranged, TextRange};

View file

@ -3,8 +3,8 @@ use itertools::Itertools;
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation}; use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::node::AstNode;
use ruff_python_ast::parenthesize::parenthesized_range; use ruff_python_ast::parenthesize::parenthesized_range;
use ruff_python_ast::AstNode;
use ruff_python_ast::{self as ast, Arguments, Expr}; use ruff_python_ast::{self as ast, Arguments, Expr};
use ruff_python_semantic::SemanticModel; use ruff_python_semantic::SemanticModel;
use ruff_text_size::Ranged; use ruff_text_size::Ranged;

View file

@ -1,6 +1,6 @@
use ruff_text_size::{Ranged, TextRange}; use ruff_text_size::{Ranged, TextRange};
use crate::node::AnyNodeRef; use crate::AnyNodeRef;
use crate::{self as ast, Expr}; use crate::{self as ast, Expr};
/// Unowned pendant to [`ast::Expr`] that stores a reference instead of a owned value. /// Unowned pendant to [`ast::Expr`] that stores a reference instead of a owned value.

View file

@ -8,9 +8,9 @@ use smallvec::SmallVec;
use ruff_text_size::{Ranged, TextRange}; use ruff_text_size::{Ranged, TextRange};
use crate::call_path::CallPath; use crate::call_path::CallPath;
use crate::node::AnyNodeRef;
use crate::parenthesize::parenthesized_range; use crate::parenthesize::parenthesized_range;
use crate::statement_visitor::{walk_body, walk_stmt, StatementVisitor}; use crate::statement_visitor::{walk_body, walk_stmt, StatementVisitor};
use crate::AnyNodeRef;
use crate::{ use crate::{
self as ast, Arguments, CmpOp, Constant, ExceptHandler, Expr, MatchCase, Pattern, Stmt, self as ast, Arguments, CmpOp, Constant, ExceptHandler, Expr, MatchCase, Pattern, Stmt,
TypeParam, TypeParam,

View file

@ -2,6 +2,7 @@ use std::path::Path;
pub use expression::*; pub use expression::*;
pub use int::*; pub use int::*;
pub use node::{AnyNode, AnyNodeRef, AstNode, NodeKind};
pub use nodes::*; pub use nodes::*;
pub mod all; pub mod all;
@ -14,7 +15,7 @@ pub mod helpers;
pub mod identifier; pub mod identifier;
pub mod imports; pub mod imports;
mod int; mod int;
pub mod node; mod node;
mod nodes; mod nodes;
pub mod parenthesize; pub mod parenthesize;
pub mod relocate; pub mod relocate;

View file

@ -1,7 +1,7 @@
use ruff_python_trivia::{BackwardsTokenizer, CommentRanges, SimpleTokenKind, SimpleTokenizer}; use ruff_python_trivia::{BackwardsTokenizer, CommentRanges, SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::{Ranged, TextLen, TextRange}; use ruff_text_size::{Ranged, TextLen, TextRange};
use crate::node::AnyNodeRef; use crate::AnyNodeRef;
use crate::ExpressionRef; use crate::ExpressionRef;
/// Returns the [`TextRange`] of a given expression including parentheses, if the expression is /// Returns the [`TextRange`] of a given expression including parentheses, if the expression is

View file

@ -1,10 +1,10 @@
use crate::node::{AnyNodeRef, AstNode};
use crate::{ use crate::{
Alias, Arguments, BoolOp, CmpOp, Comprehension, Constant, Decorator, ElifElseClause, Alias, Arguments, BoolOp, CmpOp, Comprehension, Constant, Decorator, ElifElseClause,
ExceptHandler, Expr, Keyword, MatchCase, Mod, Operator, Parameter, ParameterWithDefault, ExceptHandler, Expr, Keyword, MatchCase, Mod, Operator, Parameter, ParameterWithDefault,
Parameters, Pattern, PatternArguments, PatternKeyword, Stmt, TypeParam, TypeParams, UnaryOp, Parameters, Pattern, PatternArguments, PatternKeyword, Stmt, TypeParam, TypeParams, UnaryOp,
WithItem, WithItem,
}; };
use crate::{AnyNodeRef, AstNode};
/// Visitor that traverses all nodes recursively in pre-order. /// Visitor that traverses all nodes recursively in pre-order.
pub trait PreorderVisitor<'a> { pub trait PreorderVisitor<'a> {

View file

@ -2,12 +2,12 @@ use std::fmt::{Debug, Write};
use insta::assert_snapshot; use insta::assert_snapshot;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::visitor::preorder::{ use ruff_python_ast::visitor::preorder::{
walk_alias, walk_comprehension, walk_except_handler, walk_expr, walk_keyword, walk_match_case, walk_alias, walk_comprehension, walk_except_handler, walk_expr, walk_keyword, walk_match_case,
walk_module, walk_parameter, walk_parameters, walk_pattern, walk_stmt, walk_type_param, walk_module, walk_parameter, walk_parameters, walk_pattern, walk_stmt, walk_type_param,
walk_with_item, PreorderVisitor, walk_with_item, PreorderVisitor,
}; };
use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{ use ruff_python_ast::{
Alias, BoolOp, CmpOp, Comprehension, Constant, ExceptHandler, Expr, Keyword, MatchCase, Mod, Alias, BoolOp, CmpOp, Comprehension, Constant, ExceptHandler, Expr, Keyword, MatchCase, Mod,
Operator, Parameter, Parameters, Pattern, Stmt, TypeParam, UnaryOp, WithItem, Operator, Parameter, Parameters, Pattern, Stmt, TypeParam, UnaryOp, WithItem,

View file

@ -5,12 +5,12 @@ use ruff_python_ast as ast;
use ruff_python_parser::lexer::lex; use ruff_python_parser::lexer::lex;
use ruff_python_parser::{parse_tokens, Mode}; use ruff_python_parser::{parse_tokens, Mode};
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::visitor::{ use ruff_python_ast::visitor::{
walk_alias, walk_comprehension, walk_except_handler, walk_expr, walk_keyword, walk_match_case, walk_alias, walk_comprehension, walk_except_handler, walk_expr, walk_keyword, walk_match_case,
walk_parameter, walk_parameters, walk_pattern, walk_stmt, walk_type_param, walk_with_item, walk_parameter, walk_parameters, walk_pattern, walk_stmt, walk_type_param, walk_with_item,
Visitor, Visitor,
}; };
use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{ use ruff_python_ast::{
Alias, BoolOp, CmpOp, Comprehension, ExceptHandler, Expr, Keyword, MatchCase, Operator, Alias, BoolOp, CmpOp, Comprehension, ExceptHandler, Expr, Keyword, MatchCase, Operator,
Parameter, Parameters, Pattern, Stmt, TypeParam, UnaryOp, WithItem, Parameter, Parameters, Pattern, Stmt, TypeParam, UnaryOp, WithItem,

View file

@ -180,7 +180,7 @@ mod tests {
use insta::assert_debug_snapshot; use insta::assert_debug_snapshot;
use ruff_formatter::SourceCode; use ruff_formatter::SourceCode;
use ruff_python_ast::node::AnyNode; use ruff_python_ast::AnyNode;
use ruff_python_ast::{StmtBreak, StmtContinue}; use ruff_python_ast::{StmtBreak, StmtContinue};
use ruff_python_trivia::CommentRanges; use ruff_python_trivia::CommentRanges;
use ruff_text_size::{TextRange, TextSize}; use ruff_text_size::{TextRange, TextSize};

View file

@ -1,8 +1,8 @@
use std::borrow::Cow; use std::borrow::Cow;
use ruff_formatter::{format_args, write, FormatError, FormatOptions, SourceCode}; use ruff_formatter::{format_args, write, FormatError, FormatOptions, SourceCode};
use ruff_python_ast::node::{AnyNodeRef, AstNode};
use ruff_python_ast::PySourceType; use ruff_python_ast::PySourceType;
use ruff_python_ast::{AnyNodeRef, AstNode};
use ruff_python_trivia::{ use ruff_python_trivia::{
is_pragma_comment, lines_after, lines_after_ignoring_trivia, lines_before, is_pragma_comment, lines_after, lines_after_ignoring_trivia, lines_before,
}; };

View file

@ -96,8 +96,8 @@ pub(crate) use format::{
leading_alternate_branch_comments, leading_comments, leading_node_comments, trailing_comments, leading_alternate_branch_comments, leading_comments, leading_node_comments, trailing_comments,
}; };
use ruff_formatter::{SourceCode, SourceCodeSlice}; use ruff_formatter::{SourceCode, SourceCodeSlice};
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::visitor::preorder::{PreorderVisitor, TraversalSignal}; use ruff_python_ast::visitor::preorder::{PreorderVisitor, TraversalSignal};
use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::Mod; use ruff_python_ast::Mod;
use ruff_python_trivia::{CommentRanges, PythonWhitespace}; use ruff_python_trivia::{CommentRanges, PythonWhitespace};
use ruff_source_file::Locator; use ruff_source_file::Locator;

View file

@ -1,4 +1,4 @@
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use std::fmt::{Debug, Formatter}; use std::fmt::{Debug, Formatter};
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
@ -52,7 +52,7 @@ impl<'a> From<AnyNodeRef<'a>> for NodeRefEqualityKey<'a> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::comments::node_key::NodeRefEqualityKey; use crate::comments::node_key::NodeRefEqualityKey;
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::StmtContinue; use ruff_python_ast::StmtContinue;
use ruff_text_size::TextRange; use ruff_text_size::TextRange;
use std::collections::hash_map::DefaultHasher; use std::collections::hash_map::DefaultHasher;

View file

@ -1,7 +1,7 @@
use std::cmp::Ordering; use std::cmp::Ordering;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::whitespace::indentation; use ruff_python_ast::whitespace::indentation;
use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{self as ast, Comprehension, Expr, MatchCase, ModModule, Parameters}; use ruff_python_ast::{self as ast, Comprehension, Expr, MatchCase, ModModule, Parameters};
use ruff_python_trivia::{ use ruff_python_trivia::{
find_only_token_in_range, indentation_at_offset, BackwardsTokenizer, CommentRanges, find_only_token_in_range, indentation_at_offset, BackwardsTokenizer, CommentRanges,

View file

@ -2,7 +2,7 @@ use std::fmt::Debug;
use std::iter::Peekable; use std::iter::Peekable;
use ruff_formatter::{SourceCode, SourceCodeSlice}; use ruff_formatter::{SourceCode, SourceCodeSlice};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{Mod, Stmt}; use ruff_python_ast::{Mod, Stmt};
// The interface is designed to only export the members relevant for iterating nodes in // The interface is designed to only export the members relevant for iterating nodes in
// pre-order. // pre-order.

View file

@ -1,5 +1,5 @@
use ruff_formatter::{write, FormatRuleWithOptions}; use ruff_formatter::{write, FormatRuleWithOptions};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{Constant, Expr, ExprAttribute, ExprConstant}; use ruff_python_ast::{Constant, Expr, ExprAttribute, ExprConstant};
use ruff_python_trivia::{find_only_token_in_range, SimpleTokenKind}; use ruff_python_trivia::{find_only_token_in_range, SimpleTokenKind};
use ruff_text_size::{Ranged, TextRange}; use ruff_text_size::{Ranged, TextRange};

View file

@ -1,5 +1,5 @@
use ruff_formatter::write; use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprAwait; use ruff_python_ast::ExprAwait;
use crate::expression::maybe_parenthesize_expression; use crate::expression::maybe_parenthesize_expression;

View file

@ -1,4 +1,4 @@
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{Expr, ExprBinOp}; use ruff_python_ast::{Expr, ExprBinOp};
use crate::comments::SourceComment; use crate::comments::SourceComment;

View file

@ -1,5 +1,5 @@
use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule}; use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{BoolOp, ExprBoolOp}; use ruff_python_ast::{BoolOp, ExprBoolOp};
use crate::expression::binary_like::BinaryLike; use crate::expression::binary_like::BinaryLike;

View file

@ -1,5 +1,5 @@
use ruff_formatter::FormatRuleWithOptions; use ruff_formatter::FormatRuleWithOptions;
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{Expr, ExprCall}; use ruff_python_ast::{Expr, ExprCall};
use crate::comments::{dangling_comments, SourceComment}; use crate::comments::{dangling_comments, SourceComment};

View file

@ -1,5 +1,5 @@
use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule}; use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{CmpOp, Expr, ExprCompare}; use ruff_python_ast::{CmpOp, Expr, ExprCompare};
use crate::comments::SourceComment; use crate::comments::SourceComment;

View file

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

View file

@ -1,5 +1,5 @@
use ruff_formatter::{format_args, write}; use ruff_formatter::{format_args, write};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{Expr, ExprDict}; use ruff_python_ast::{Expr, ExprDict};
use ruff_text_size::{Ranged, TextRange}; use ruff_text_size::{Ranged, TextRange};

View file

@ -1,5 +1,5 @@
use ruff_formatter::write; use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprDictComp; use ruff_python_ast::ExprDictComp;
use ruff_text_size::Ranged; use ruff_text_size::Ranged;

View file

@ -2,7 +2,7 @@ use memchr::memchr2;
use crate::comments::SourceComment; use crate::comments::SourceComment;
use ruff_formatter::FormatResult; use ruff_formatter::FormatResult;
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprFString; use ruff_python_ast::ExprFString;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses}; use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};

View file

@ -1,4 +1,4 @@
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprFormattedValue; use ruff_python_ast::ExprFormattedValue;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses}; use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};

View file

@ -1,5 +1,5 @@
use ruff_formatter::{format_args, write, FormatRuleWithOptions}; use ruff_formatter::{format_args, write, FormatRuleWithOptions};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprGeneratorExp; use ruff_python_ast::ExprGeneratorExp;
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::{Ranged, TextRange}; use ruff_text_size::{Ranged, TextRange};

View file

@ -1,5 +1,5 @@
use ruff_formatter::{write, FormatRuleWithOptions}; use ruff_formatter::{write, FormatRuleWithOptions};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{Expr, ExprIfExp}; use ruff_python_ast::{Expr, ExprIfExp};
use crate::comments::leading_comments; use crate::comments::leading_comments;

View file

@ -1,5 +1,5 @@
use ruff_formatter::write; use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprLambda; use ruff_python_ast::ExprLambda;
use ruff_text_size::Ranged; use ruff_text_size::Ranged;

View file

@ -1,5 +1,5 @@
use ruff_formatter::prelude::format_with; use ruff_formatter::prelude::format_with;
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprList; use ruff_python_ast::ExprList;
use ruff_text_size::Ranged; use ruff_text_size::Ranged;

View file

@ -1,5 +1,5 @@
use ruff_formatter::{format_args, write, FormatResult}; use ruff_formatter::{format_args, write, FormatResult};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprListComp; use ruff_python_ast::ExprListComp;
use crate::comments::SourceComment; use crate::comments::SourceComment;

View file

@ -1,5 +1,5 @@
use ruff_formatter::{write, FormatContext}; use ruff_formatter::{write, FormatContext};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprName; use ruff_python_ast::ExprName;
use crate::comments::SourceComment; use crate::comments::SourceComment;

View file

@ -1,5 +1,5 @@
use ruff_formatter::{format_args, write}; use ruff_formatter::{format_args, write};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprNamedExpr; use ruff_python_ast::ExprNamedExpr;
use crate::comments::{dangling_comments, SourceComment}; use crate::comments::{dangling_comments, SourceComment};

View file

@ -1,4 +1,4 @@
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprSet; use ruff_python_ast::ExprSet;
use ruff_text_size::Ranged; use ruff_text_size::Ranged;

View file

@ -1,5 +1,5 @@
use ruff_formatter::{format_args, write, Buffer, FormatResult}; use ruff_formatter::{format_args, write, Buffer, FormatResult};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprSetComp; use ruff_python_ast::ExprSetComp;
use crate::comments::SourceComment; use crate::comments::SourceComment;

View file

@ -1,5 +1,5 @@
use ruff_formatter::{write, FormatError}; use ruff_formatter::{write, FormatError};
use ruff_python_ast::node::{AnyNodeRef, AstNode}; use ruff_python_ast::{AnyNodeRef, AstNode};
use ruff_python_ast::{Expr, ExprSlice, ExprUnaryOp, UnaryOp}; use ruff_python_ast::{Expr, ExprSlice, ExprUnaryOp, UnaryOp};
use ruff_python_trivia::{SimpleToken, SimpleTokenKind, SimpleTokenizer}; use ruff_python_trivia::{SimpleToken, SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::{Ranged, TextRange}; use ruff_text_size::{Ranged, TextRange};

View file

@ -1,5 +1,5 @@
use ruff_formatter::write; use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprStarred; use ruff_python_ast::ExprStarred;
use crate::comments::{dangling_comments, SourceComment}; use crate::comments::{dangling_comments, SourceComment};

View file

@ -1,5 +1,5 @@
use ruff_formatter::{write, FormatRuleWithOptions}; use ruff_formatter::{write, FormatRuleWithOptions};
use ruff_python_ast::node::{AnyNodeRef, AstNode}; use ruff_python_ast::{AnyNodeRef, AstNode};
use ruff_python_ast::{Expr, ExprSubscript}; use ruff_python_ast::{Expr, ExprSubscript};
use crate::comments::SourceComment; use crate::comments::SourceComment;

View file

@ -1,5 +1,5 @@
use ruff_formatter::{format_args, write, FormatRuleWithOptions}; use ruff_formatter::{format_args, write, FormatRuleWithOptions};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprTuple; use ruff_python_ast::ExprTuple;
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::{Ranged, TextRange}; use ruff_text_size::{Ranged, TextRange};

View file

@ -1,4 +1,4 @@
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprUnaryOp; use ruff_python_ast::ExprUnaryOp;
use ruff_python_ast::UnaryOp; use ruff_python_ast::UnaryOp;

View file

@ -1,5 +1,5 @@
use ruff_formatter::write; use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{Expr, ExprYield, ExprYieldFrom}; use ruff_python_ast::{Expr, ExprYield, ExprYieldFrom};
use ruff_text_size::{Ranged, TextRange}; use ruff_text_size::{Ranged, TextRange};

View file

@ -1,4 +1,4 @@
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExprYieldFrom; use ruff_python_ast::ExprYieldFrom;
use crate::expression::expr_yield::AnyExpressionYield; use crate::expression::expr_yield::AnyExpressionYield;

View file

@ -6,8 +6,8 @@ use ruff_formatter::{
write, FormatOwnedWithRule, FormatRefWithRule, FormatRule, FormatRuleWithOptions, write, FormatOwnedWithRule, FormatRefWithRule, FormatRule, FormatRuleWithOptions,
}; };
use ruff_python_ast as ast; use ruff_python_ast as ast;
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::visitor::preorder::{walk_expr, PreorderVisitor}; use ruff_python_ast::visitor::preorder::{walk_expr, PreorderVisitor};
use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{Constant, Expr, ExpressionRef, Operator}; use ruff_python_ast::{Constant, Expr, ExpressionRef, Operator};
use ruff_python_trivia::CommentRanges; use ruff_python_trivia::CommentRanges;

View file

@ -1,6 +1,6 @@
use ruff_formatter::prelude::tag::Condition; use ruff_formatter::prelude::tag::Condition;
use ruff_formatter::{format_args, write, Argument, Arguments}; use ruff_formatter::{format_args, write, Argument, Arguments};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExpressionRef; use ruff_python_ast::ExpressionRef;
use ruff_python_trivia::CommentRanges; use ruff_python_trivia::CommentRanges;
use ruff_python_trivia::{ use ruff_python_trivia::{

View file

@ -3,7 +3,7 @@ use std::borrow::Cow;
use bitflags::bitflags; use bitflags::bitflags;
use ruff_formatter::{format_args, write, FormatError}; use ruff_formatter::{format_args, write, FormatError};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{self as ast, Constant, ExprConstant, ExprFString, ExpressionRef}; use ruff_python_ast::{self as ast, Constant, ExprConstant, ExprFString, ExpressionRef};
use ruff_python_parser::lexer::{lex_starts_at, LexicalError, LexicalErrorType}; use ruff_python_parser::lexer::{lex_starts_at, LexicalError, LexicalErrorType};
use ruff_python_parser::{Mode, Tok}; use ruff_python_parser::{Mode, Tok};

View file

@ -3,7 +3,7 @@ use tracing::Level;
use ruff_formatter::prelude::*; use ruff_formatter::prelude::*;
use ruff_formatter::{format, FormatError, Formatted, PrintError, Printed, SourceCode}; use ruff_formatter::{format, FormatError, Formatted, PrintError, Printed, SourceCode};
use ruff_python_ast::node::AstNode; use ruff_python_ast::AstNode;
use ruff_python_ast::Mod; use ruff_python_ast::Mod;
use ruff_python_index::tokens_and_ranges; use ruff_python_index::tokens_and_ranges;
use ruff_python_parser::lexer::LexicalError; use ruff_python_parser::lexer::LexicalError;

View file

@ -1,5 +1,5 @@
use ruff_formatter::write; use ruff_formatter::write;
use ruff_python_ast::node::AstNode; use ruff_python_ast::AstNode;
use ruff_python_ast::MatchCase; use ruff_python_ast::MatchCase;
use crate::builders::parenthesize_if_expands; use crate::builders::parenthesize_if_expands;

View file

@ -1,8 +1,8 @@
use std::usize; use std::usize;
use ruff_formatter::{format_args, write, FormatRuleWithOptions}; use ruff_formatter::{format_args, write, FormatRuleWithOptions};
use ruff_python_ast::node::{AnyNodeRef, AstNode};
use ruff_python_ast::Parameters; use ruff_python_ast::Parameters;
use ruff_python_ast::{AnyNodeRef, AstNode};
use ruff_python_trivia::{SimpleToken, SimpleTokenKind, SimpleTokenizer}; use ruff_python_trivia::{SimpleToken, SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::{Ranged, TextRange, TextSize}; use ruff_text_size::{Ranged, TextRange, TextSize};

View file

@ -1,5 +1,5 @@
use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule, FormatRule, FormatRuleWithOptions}; use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule, FormatRule, FormatRuleWithOptions};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::Pattern; use ruff_python_ast::Pattern;
use ruff_python_trivia::CommentRanges; use ruff_python_trivia::CommentRanges;
use ruff_python_trivia::{ use ruff_python_trivia::{

View file

@ -1,5 +1,5 @@
use ruff_formatter::write; use ruff_formatter::write;
use ruff_python_ast::node::AstNode; use ruff_python_ast::AstNode;
use ruff_python_ast::{Pattern, PatternArguments}; use ruff_python_ast::{Pattern, PatternArguments};
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::{Ranged, TextRange, TextSize}; use ruff_text_size::{Ranged, TextRange, TextSize};

View file

@ -1,5 +1,5 @@
use ruff_formatter::write; use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::PatternMatchAs; use ruff_python_ast::PatternMatchAs;
use crate::comments::{dangling_comments, SourceComment}; use crate::comments::{dangling_comments, SourceComment};

View file

@ -1,5 +1,5 @@
use ruff_formatter::write; use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::PatternMatchClass; use ruff_python_ast::PatternMatchClass;
use crate::comments::{dangling_comments, SourceComment}; use crate::comments::{dangling_comments, SourceComment};

View file

@ -1,5 +1,5 @@
use ruff_formatter::{format_args, write}; use ruff_formatter::{format_args, write};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::PatternMatchMapping; use ruff_python_ast::PatternMatchMapping;
use ruff_python_ast::{Expr, Identifier, Pattern}; use ruff_python_ast::{Expr, Identifier, Pattern};
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};

View file

@ -1,5 +1,5 @@
use ruff_formatter::write; use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::PatternMatchOr; use ruff_python_ast::PatternMatchOr;
use crate::comments::leading_comments; use crate::comments::leading_comments;

View file

@ -1,6 +1,6 @@
use crate::comments::SourceComment; use crate::comments::SourceComment;
use ruff_formatter::{format_args, Format, FormatResult}; use ruff_formatter::{format_args, Format, FormatResult};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::PatternMatchSequence; use ruff_python_ast::PatternMatchSequence;
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::{Ranged, TextRange}; use ruff_text_size::{Ranged, TextRange};

View file

@ -1,4 +1,4 @@
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{Constant, PatternMatchSingleton}; use ruff_python_ast::{Constant, PatternMatchSingleton};
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses}; use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};

View file

@ -1,5 +1,5 @@
use ruff_formatter::write; use ruff_formatter::write;
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::PatternMatchStar; use ruff_python_ast::PatternMatchStar;
use crate::comments::{dangling_comments, SourceComment}; use crate::comments::{dangling_comments, SourceComment};

View file

@ -1,4 +1,4 @@
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::PatternMatchValue; use ruff_python_ast::PatternMatchValue;
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses, Parentheses}; use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses, Parentheses};

View file

@ -1,5 +1,5 @@
use ruff_formatter::{write, Argument, Arguments, FormatError}; use ruff_formatter::{write, Argument, Arguments, FormatError};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{ use ruff_python_ast::{
ElifElseClause, ExceptHandlerExceptHandler, MatchCase, StmtClassDef, StmtFor, StmtFunctionDef, ElifElseClause, ExceptHandlerExceptHandler, MatchCase, StmtClassDef, StmtFor, StmtFunctionDef,
StmtIf, StmtMatch, StmtTry, StmtWhile, StmtWith, Suite, StmtIf, StmtMatch, StmtTry, StmtWhile, StmtWith, Suite,

View file

@ -1,5 +1,5 @@
use ruff_formatter::{format_args, write}; use ruff_formatter::{format_args, write};
use ruff_python_ast::node::AstNode; use ruff_python_ast::AstNode;
use ruff_python_ast::StmtGlobal; use ruff_python_ast::StmtGlobal;
use crate::comments::{SourceComment, SuppressionKind}; use crate::comments::{SourceComment, SuppressionKind};

View file

@ -1,5 +1,5 @@
use ruff_formatter::{format_args, write}; use ruff_formatter::{format_args, write};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{ElifElseClause, StmtIf}; use ruff_python_ast::{ElifElseClause, StmtIf};
use crate::comments::SourceComment; use crate::comments::SourceComment;

View file

@ -1,5 +1,5 @@
use ruff_formatter::write; use ruff_formatter::write;
use ruff_python_ast::node::AstNode; use ruff_python_ast::AstNode;
use ruff_python_ast::StmtImportFrom; use ruff_python_ast::StmtImportFrom;
use ruff_text_size::Ranged; use ruff_text_size::Ranged;

View file

@ -1,5 +1,5 @@
use ruff_formatter::{format_args, write}; use ruff_formatter::{format_args, write};
use ruff_python_ast::node::AstNode; use ruff_python_ast::AstNode;
use ruff_python_ast::StmtNonlocal; use ruff_python_ast::StmtNonlocal;
use crate::comments::{SourceComment, SuppressionKind}; use crate::comments::{SourceComment, SuppressionKind};

View file

@ -1,5 +1,5 @@
use ruff_formatter::{format_args, write}; use ruff_formatter::{format_args, write};
use ruff_python_ast::node::AstNode; use ruff_python_ast::AstNode;
use ruff_python_ast::{Stmt, StmtWhile}; use ruff_python_ast::{Stmt, StmtWhile};
use ruff_text_size::Ranged; use ruff_text_size::Ranged;

View file

@ -1,5 +1,5 @@
use ruff_formatter::{format_args, write, FormatError}; use ruff_formatter::{format_args, write, FormatError};
use ruff_python_ast::node::AstNode; use ruff_python_ast::AstNode;
use ruff_python_ast::StmtWith; use ruff_python_ast::StmtWith;
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};
use ruff_text_size::{Ranged, TextRange}; use ruff_text_size::{Ranged, TextRange};

View file

@ -1,6 +1,6 @@
use ruff_formatter::{write, FormatOwnedWithRule, FormatRefWithRule, FormatRuleWithOptions}; use ruff_formatter::{write, FormatOwnedWithRule, FormatRefWithRule, FormatRuleWithOptions};
use ruff_python_ast::helpers::is_compound_statement; use ruff_python_ast::helpers::is_compound_statement;
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::{self as ast, Constant, Expr, ExprConstant, PySourceType, Stmt, Suite}; use ruff_python_ast::{self as ast, Constant, Expr, ExprConstant, PySourceType, Stmt, Suite};
use ruff_python_trivia::{lines_after, lines_after_ignoring_end_of_line_trivia, lines_before}; use ruff_python_trivia::{lines_after, lines_after_ignoring_end_of_line_trivia, lines_before};
use ruff_text_size::{Ranged, TextRange}; use ruff_text_size::{Ranged, TextRange};

View file

@ -1,6 +1,6 @@
use ruff_formatter::write; use ruff_formatter::write;
use ruff_formatter::FormatResult; use ruff_formatter::FormatResult;
use ruff_python_ast::node::AstNode; use ruff_python_ast::AstNode;
use ruff_python_ast::TypeParams; use ruff_python_ast::TypeParams;
use ruff_text_size::Ranged; use ruff_text_size::Ranged;

View file

@ -4,7 +4,7 @@ use std::iter::FusedIterator;
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
use ruff_formatter::{write, FormatError}; use ruff_formatter::{write, FormatError};
use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::Stmt; use ruff_python_ast::Stmt;
use ruff_python_parser::lexer::{lex_starts_at, LexResult}; use ruff_python_parser::lexer::{lex_starts_at, LexResult};
use ruff_python_parser::{Mode, Tok}; use ruff_python_parser::{Mode, Tok};

View file

@ -74,11 +74,11 @@ impl<'a> Index<NodeId> for Nodes<'a> {
} }
} }
/// A reference to an AST node. Like [`ruff_python_ast::node::AnyNodeRef`], but wraps the node /// A reference to an AST node. Like [`ruff_python_ast::AnyNodeRef`], but wraps the node
/// itself (like [`Stmt`]) rather than the narrowed type (like [`ruff_python_ast::StmtAssign`]). /// itself (like [`Stmt`]) rather than the narrowed type (like [`ruff_python_ast::StmtAssign`]).
/// ///
/// TODO(charlie): Replace with [`ruff_python_ast::node::AnyNodeRef`]. This requires migrating /// TODO(charlie): Replace with [`ruff_python_ast::AnyNodeRef`]. This requires migrating
/// the rest of the codebase to use [`ruff_python_ast::node::AnyNodeRef`] and related abstractions, /// the rest of the codebase to use [`ruff_python_ast::AnyNodeRef`] and related abstractions,
/// like [`ruff_python_ast::ExpressionRef`] instead of [`Expr`]. /// like [`ruff_python_ast::ExpressionRef`] instead of [`Expr`].
#[derive(Copy, Clone, Debug, PartialEq)] #[derive(Copy, Clone, Debug, PartialEq)]
pub enum NodeRef<'a> { pub enum NodeRef<'a> {