Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove AstNode and AnyNode #15479

Merged
merged 7 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
use ruff_macros::{derive_message_formats, ViolationMetadata};
use ruff_python_ast::comparable::ComparableExpr;
use ruff_python_ast::parenthesize::parenthesized_range;
use ruff_python_ast::AstNode;
use ruff_python_ast::{self as ast, Expr, ExprCall, ExprContext};
use ruff_python_codegen::Generator;
use ruff_python_trivia::CommentRanges;
Expand Down Expand Up @@ -324,7 +323,7 @@ fn get_parametrize_name_range(
) -> Option<TextRange> {
parenthesized_range(
expr.into(),
call.arguments.as_any_node_ref(),
(&call.arguments).into(),
comment_ranges,
source,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ops::Range;
use ruff_diagnostics::{AlwaysFixableViolation, Applicability, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, ViolationMetadata};
use ruff_python_ast::parenthesize::parenthesized_range;
use ruff_python_ast::{AstNode, Expr, ExprBinOp, ExprCall, Operator};
use ruff_python_ast::{Expr, ExprBinOp, ExprCall, Operator};
use ruff_python_semantic::SemanticModel;
use ruff_python_trivia::CommentRanges;
use ruff_text_size::{Ranged, TextRange};
Expand Down Expand Up @@ -134,12 +134,6 @@ fn parent_and_next_path_fragment_range(

Some((
parent.range(),
parenthesized_range(
right.into(),
parent.as_any_node_ref(),
comment_ranges,
source,
)
.unwrap_or(range),
parenthesized_range(right.into(), parent.into(), comment_ranges, source).unwrap_or(range),
))
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
use ruff_macros::{derive_message_formats, ViolationMetadata};
use ruff_python_ast::parenthesize::parenthesized_range;
use ruff_python_ast::{
self as ast, AstNode, Expr, ExprEllipsisLiteral, ExprLambda, Identifier, Parameter,
self as ast, Expr, ExprEllipsisLiteral, ExprLambda, Identifier, Parameter,
ParameterWithDefault, Parameters, Stmt,
};
use ruff_python_semantic::SemanticModel;
Expand Down Expand Up @@ -263,7 +263,7 @@ fn replace_trailing_ellipsis_with_original_expr(
) -> String {
let original_expr_range = parenthesized_range(
(&lambda.body).into(),
lambda.as_any_node_ref(),
lambda.into(),
checker.comment_ranges(),
checker.source(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ruff_macros::{derive_message_formats, ViolationMetadata};
use ruff_python_ast as ast;
use ruff_python_ast::comparable::ComparableExpr;
use ruff_python_ast::parenthesize::parenthesized_range;
use ruff_python_ast::{AstNode, ExprBinOp, ExpressionRef, Operator};
use ruff_python_ast::{ExprBinOp, ExpressionRef, Operator};
use ruff_text_size::{Ranged, TextRange};

use crate::checkers::ast::Checker;
Expand Down Expand Up @@ -147,7 +147,7 @@ fn augmented_assignment(
let locator = checker.locator();

let right_operand_ref = ExpressionRef::from(right_operand);
let parent = original_expr.as_any_node_ref();
let parent = original_expr.into();
let comment_ranges = checker.comment_ranges();
let source = checker.source();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use itertools::Itertools;
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, ViolationMetadata};
use ruff_python_ast::parenthesize::parenthesized_range;
use ruff_python_ast::AstNode;
use ruff_python_ast::{self as ast, Arguments, Expr};
use ruff_python_semantic::SemanticModel;
use ruff_text_size::Ranged;
Expand Down Expand Up @@ -110,7 +109,7 @@ fn convert_to_reduce(iterable: &Expr, call: &ast::ExprCall, checker: &Checker) -
let iterable = checker.locator().slice(
parenthesized_range(
iterable.into(),
call.arguments.as_any_node_ref(),
(&call.arguments).into(),
checker.comment_ranges(),
checker.locator().contents(),
)
Expand Down
5 changes: 2 additions & 3 deletions crates/ruff_python_ast/ast.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
# is, `StmtIf` will become `if_stmt`.)
#
# anynode_is_label: foo_bar
# Controls the name of the AnyNode::foo_bar, AnyNode::is_foo_bar, and
# AnyNodeRef::is_foo_bar methods. The default is the group name in
# snake_case.
# Controls the name of the AnyNodeRef::is_foo_bar method. The default is the
# group name in snake_case.
#
# ref_enum_ty:
# The name of the reference enum that we create for this group. The default
Expand Down
Loading
Loading