mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-19 03:48:29 +00:00
[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:
parent
84a810736d
commit
04e7cecab3
3 changed files with 32 additions and 2 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue