Implement iter(), len() and is_empty() for all display-literal AST nodes (#12807)
This commit is contained in:
@@ -193,7 +193,7 @@ impl FormatNodeRule<ExprTuple> for FormatExprTuple {
|
||||
TupleParentheses::NeverPreserve => {
|
||||
optional_parentheses(&ExprSequence::new(item)).fmt(f)
|
||||
}
|
||||
TupleParentheses::OptionalParentheses if item.elts.len() == 2 => {
|
||||
TupleParentheses::OptionalParentheses if item.len() == 2 => {
|
||||
optional_parentheses(&ExprSequence::new(item)).fmt(f)
|
||||
}
|
||||
TupleParentheses::Default | TupleParentheses::OptionalParentheses => {
|
||||
|
||||
@@ -1052,7 +1052,7 @@ pub(crate) fn has_own_parentheses(
|
||||
..
|
||||
},
|
||||
) => {
|
||||
if !tuple.elts.is_empty() || context.comments().has_dangling(AnyNodeRef::from(expr)) {
|
||||
if !tuple.is_empty() || context.comments().has_dangling(AnyNodeRef::from(expr)) {
|
||||
Some(OwnParentheses::NonEmpty)
|
||||
} else {
|
||||
Some(OwnParentheses::Empty)
|
||||
@@ -1216,10 +1216,10 @@ pub(crate) fn is_splittable_expression(expr: &Expr, context: &PyFormatContext) -
|
||||
| Expr::YieldFrom(_) => true,
|
||||
|
||||
// Sequence types can split if they contain at least one element.
|
||||
Expr::Tuple(tuple) => !tuple.elts.is_empty(),
|
||||
Expr::Dict(dict) => !dict.items.is_empty(),
|
||||
Expr::Set(set) => !set.elts.is_empty(),
|
||||
Expr::List(list) => !list.elts.is_empty(),
|
||||
Expr::Tuple(tuple) => !tuple.is_empty(),
|
||||
Expr::Dict(dict) => !dict.is_empty(),
|
||||
Expr::Set(set) => !set.is_empty(),
|
||||
Expr::List(list) => !list.is_empty(),
|
||||
|
||||
Expr::UnaryOp(unary) => is_splittable_expression(unary.operand.as_ref(), context),
|
||||
Expr::Yield(ast::ExprYield { value, .. }) => value.is_some(),
|
||||
|
||||
Reference in New Issue
Block a user