[flake8-simplify] Fix SIM222 false positive for tuple(generator) or None (SIM222) (#21187)

Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
Dan Parizher 2025-11-10 08:27:31 -05:00 committed by GitHub
parent 84a810736d
commit 04e7cecab3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 2 deletions

View file

@ -1318,9 +1318,19 @@ impl Truthiness {
if arguments.is_empty() {
// Ex) `list()`
Self::Falsey
} else if arguments.args.len() == 1 && arguments.keywords.is_empty() {
} else if let [argument] = &*arguments.args
&& arguments.keywords.is_empty()
{
// Ex) `list([1, 2, 3])`
Self::from_expr(&arguments.args[0], is_builtin)
// For tuple(generator), we can't determine statically if the result will
// be empty or not, so return Unknown. The generator itself is truthy, but
// tuple(empty_generator) is falsy. ListComp and SetComp are handled by
// recursing into Self::from_expr below, which returns Unknown for them.
if argument.is_generator_expr() {
Self::Unknown
} else {
Self::from_expr(argument, is_builtin)
}
} else {
Self::Unknown
}