mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-10 10:22:14 +00:00
Remove AstNode
and AnyNode
(#15479)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
While looking into potential AST optimizations, I noticed the `AstNode` trait and `AnyNode` type aren't used anywhere in Ruff or Red Knot. It looks like they might be historical artifacts of previous ways of consuming AST nodes? - `AstNode::cast`, `AstNode::cast_ref`, and `AstNode::can_cast` are not used anywhere. - Since `cast_ref` isn't needed anymore, the `Ref` associated type isn't either. This is a pure refactoring, with no intended behavior changes.
This commit is contained in:
parent
8e3633f55a
commit
98ef564170
24 changed files with 52 additions and 5349 deletions
|
@ -1,5 +1,5 @@
|
|||
use ruff_formatter::{write, FormatError};
|
||||
use ruff_python_ast::{AnyNodeRef, AstNode};
|
||||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::{Expr, ExprSlice, ExprUnaryOp, UnaryOp};
|
||||
use ruff_python_trivia::{SimpleToken, SimpleTokenKind, SimpleTokenizer};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
@ -36,7 +36,7 @@ impl FormatNodeRule<ExprSlice> for FormatExprSlice {
|
|||
// to handle newlines and spacing, or the node is None and we insert the corresponding
|
||||
// slice of dangling comments
|
||||
let comments = f.context().comments().clone();
|
||||
let slice_dangling_comments = comments.dangling(item.as_any_node_ref());
|
||||
let slice_dangling_comments = comments.dangling(item);
|
||||
// Put the dangling comments (where the nodes are missing) into buckets
|
||||
let first_colon_partition_index =
|
||||
slice_dangling_comments.partition_point(|x| x.start() < first_colon.start());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use ruff_formatter::{write, FormatRuleWithOptions};
|
||||
use ruff_python_ast::{AnyNodeRef, AstNode};
|
||||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::{Expr, ExprSubscript};
|
||||
|
||||
use crate::expression::expr_tuple::TupleParentheses;
|
||||
|
@ -35,7 +35,7 @@ impl FormatNodeRule<ExprSubscript> for FormatExprSubscript {
|
|||
let call_chain_layout = self.call_chain_layout.apply_in_node(item, f);
|
||||
|
||||
let comments = f.context().comments().clone();
|
||||
let dangling_comments = comments.dangling(item.as_any_node_ref());
|
||||
let dangling_comments = comments.dangling(item);
|
||||
debug_assert!(
|
||||
dangling_comments.len() <= 1,
|
||||
"A subscript expression can only have a single dangling comment, the one after the bracket"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue