mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
[flake8-simplify
] Infer "unknown" truthiness for literal iterables whose items are all unpacks (SIM222
) (#14263)
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 (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz (push) Blocked by required conditions
CI / Fuzz the 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 (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz (push) Blocked by required conditions
CI / Fuzz the 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
## Summary Resolves #14237. ## Test Plan `cargo nextest run` and `cargo insta test`. --------- Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
This commit is contained in:
parent
f1f3bd1cd3
commit
be69f61b3e
3 changed files with 51 additions and 6 deletions
|
@ -12,8 +12,8 @@ use crate::parenthesize::parenthesized_range;
|
|||
use crate::statement_visitor::StatementVisitor;
|
||||
use crate::visitor::Visitor;
|
||||
use crate::{
|
||||
self as ast, Arguments, CmpOp, ExceptHandler, Expr, FStringElement, MatchCase, Operator,
|
||||
Pattern, Stmt, TypeParam,
|
||||
self as ast, Arguments, CmpOp, DictItem, ExceptHandler, Expr, FStringElement, MatchCase,
|
||||
Operator, Pattern, Stmt, TypeParam,
|
||||
};
|
||||
use crate::{AnyNodeRef, ExprContext};
|
||||
|
||||
|
@ -1188,14 +1188,32 @@ impl Truthiness {
|
|||
| Expr::Set(ast::ExprSet { elts, .. })
|
||||
| Expr::Tuple(ast::ExprTuple { elts, .. }) => {
|
||||
if elts.is_empty() {
|
||||
Self::Falsey
|
||||
return Self::Falsey;
|
||||
}
|
||||
|
||||
if elts.iter().all(Expr::is_starred_expr) {
|
||||
// [*foo] / [*foo, *bar]
|
||||
Self::Unknown
|
||||
} else {
|
||||
Self::Truthy
|
||||
}
|
||||
}
|
||||
Expr::Dict(dict) => {
|
||||
if dict.is_empty() {
|
||||
Self::Falsey
|
||||
return Self::Falsey;
|
||||
}
|
||||
|
||||
if dict.items.iter().all(|item| {
|
||||
matches!(
|
||||
item,
|
||||
DictItem {
|
||||
key: None,
|
||||
value: Expr::Name(..)
|
||||
}
|
||||
)
|
||||
}) {
|
||||
// {**foo} / {**foo, **bar}
|
||||
Self::Unknown
|
||||
} else {
|
||||
Self::Truthy
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue