[flake8-bandit] Fix truthiness: dict-only ** displays not truthy for shell (S602, S604, S609) (#20177)

## Summary
Fixes #19927
This commit is contained in:
Dan Parizher 2025-09-10 17:06:33 -04:00 committed by GitHub
parent cde5e4e343
commit 4c64ba4ee1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 42 additions and 16 deletions

View file

@ -1294,15 +1294,14 @@ impl Truthiness {
return Self::Falsey;
}
if dict.items.iter().all(|item| {
matches!(
item,
DictItem {
key: None,
value: Expr::Name(..)
}
)
}) {
// If the dict consists only of double-starred items (e.g., {**x, **y}),
// consider its truthiness unknown. This matches lists/sets/tuples containing
// only starred elements, which are also Unknown.
if dict
.items
.iter()
.all(|item| matches!(item, DictItem { key: None, .. }))
{
// {**foo} / {**foo, **bar}
Self::Unknown
} else {