Remove customizable reference enum names (#15647)

The AST generator creates a reference enum for each syntax group — an
enum where each variant contains a reference to the relevant syntax
node. Previously you could customize the name of the reference enum for
a group — primarily because there was an existing `ExpressionRef` type
that wouldn't have lined up with the auto-derived name `ExprRef`. This
follow-up PR is a simple search/replace to switch over to the
auto-derived name, so that we can remove this customization point.
This commit is contained in:
Douglas Creager 2025-01-21 13:46:31 -05:00 committed by GitHub
parent fa546b20a6
commit ef85c682bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 223 additions and 231 deletions

View file

@ -7,7 +7,7 @@ use ruff_formatter::{
use ruff_python_ast::parenthesize::parentheses_iterator;
use ruff_python_ast::visitor::source_order::{walk_expr, SourceOrderVisitor};
use ruff_python_ast::{self as ast};
use ruff_python_ast::{AnyNodeRef, Expr, ExpressionRef, Operator};
use ruff_python_ast::{AnyNodeRef, Expr, ExprRef, Operator};
use ruff_python_trivia::CommentRanges;
use ruff_text_size::Ranged;
@ -881,14 +881,14 @@ pub enum CallChainLayout {
impl CallChainLayout {
pub(crate) fn from_expression(
mut expr: ExpressionRef,
mut expr: ExprRef,
comment_ranges: &CommentRanges,
source: &str,
) -> Self {
let mut attributes_after_parentheses = 0;
loop {
match expr {
ExpressionRef::Attribute(ast::ExprAttribute { value, .. }) => {
ExprRef::Attribute(ast::ExprAttribute { value, .. }) => {
// ```
// f().g
// ^^^ value
@ -903,7 +903,7 @@ impl CallChainLayout {
attributes_after_parentheses += 1;
}
expr = ExpressionRef::from(value.as_ref());
expr = ExprRef::from(value.as_ref());
}
// ```
// f()
@ -913,9 +913,9 @@ impl CallChainLayout {
// ^^^^^^^^^^ expr
// ^^^^ value
// ```
ExpressionRef::Call(ast::ExprCall { func: inner, .. })
| ExpressionRef::Subscript(ast::ExprSubscript { value: inner, .. }) => {
expr = ExpressionRef::from(inner.as_ref());
ExprRef::Call(ast::ExprCall { func: inner, .. })
| ExprRef::Subscript(ast::ExprSubscript { value: inner, .. }) => {
expr = ExprRef::from(inner.as_ref());
}
_ => {
// We to format the following in fluent style:
@ -947,7 +947,7 @@ impl CallChainLayout {
/// formatting
pub(crate) fn apply_in_node<'a>(
self,
item: impl Into<ExpressionRef<'a>>,
item: impl Into<ExprRef<'a>>,
f: &mut PyFormatter,
) -> CallChainLayout {
match self {

View file

@ -1,7 +1,7 @@
use ruff_formatter::prelude::tag::Condition;
use ruff_formatter::{format_args, write, Argument, Arguments};
use ruff_python_ast::AnyNodeRef;
use ruff_python_ast::ExpressionRef;
use ruff_python_ast::ExprRef;
use ruff_python_trivia::CommentRanges;
use ruff_python_trivia::{
first_non_trivia_token, BackwardsTokenizer, SimpleToken, SimpleTokenKind,
@ -93,9 +93,9 @@ pub enum Parentheses {
Never,
}
/// Returns `true` if the [`ExpressionRef`] is enclosed by parentheses in the source code.
/// Returns `true` if the [`ExprRef`] is enclosed by parentheses in the source code.
pub(crate) fn is_expression_parenthesized(
expr: ExpressionRef,
expr: ExprRef,
comment_ranges: &CommentRanges,
contents: &str,
) -> bool {
@ -449,7 +449,7 @@ impl Format<PyFormatContext<'_>> for FormatEmptyParenthesized<'_> {
#[cfg(test)]
mod tests {
use ruff_python_ast::ExpressionRef;
use ruff_python_ast::ExprRef;
use ruff_python_parser::parse_expression;
use ruff_python_trivia::CommentRanges;
@ -460,7 +460,7 @@ mod tests {
let expression = r#"(b().c("")).d()"#;
let parsed = parse_expression(expression).unwrap();
assert!(!is_expression_parenthesized(
ExpressionRef::from(parsed.expr()),
ExprRef::from(parsed.expr()),
&CommentRanges::default(),
expression
));