mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-26 13:24:23 +00:00
Implement iter()
, len()
and is_empty()
for all display-literal AST nodes (#12807)
This commit is contained in:
parent
a99a45868c
commit
aa0db338d9
56 changed files with 304 additions and 240 deletions
|
@ -582,8 +582,8 @@ pub const fn is_singleton(expr: &Expr) -> bool {
|
|||
|
||||
/// Return `true` if the [`Expr`] is a literal or tuple of literals.
|
||||
pub fn is_constant(expr: &Expr) -> bool {
|
||||
if let Expr::Tuple(ast::ExprTuple { elts, .. }) = expr {
|
||||
elts.iter().all(is_constant)
|
||||
if let Expr::Tuple(tuple) = expr {
|
||||
tuple.iter().all(is_constant)
|
||||
} else {
|
||||
expr.is_literal_expr()
|
||||
}
|
||||
|
@ -630,8 +630,8 @@ pub fn extract_handled_exceptions(handlers: &[ExceptHandler]) -> Vec<&Expr> {
|
|||
match handler {
|
||||
ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler { type_, .. }) => {
|
||||
if let Some(type_) = type_ {
|
||||
if let Expr::Tuple(ast::ExprTuple { elts, .. }) = &type_.as_ref() {
|
||||
for type_ in elts {
|
||||
if let Expr::Tuple(tuple) = &**type_ {
|
||||
for type_ in tuple {
|
||||
handled_exceptions.push(type_);
|
||||
}
|
||||
} else {
|
||||
|
@ -1185,8 +1185,8 @@ impl Truthiness {
|
|||
Self::Truthy
|
||||
}
|
||||
}
|
||||
Expr::Dict(ast::ExprDict { items, .. }) => {
|
||||
if items.is_empty() {
|
||||
Expr::Dict(dict) => {
|
||||
if dict.is_empty() {
|
||||
Self::Falsey
|
||||
} else {
|
||||
Self::Truthy
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue