ruff/crates/ruff_linter/resources/test/fixtures/flake8_simplify
Dan Parizher f052bd644c
[`flake8-simplify`] Fix truthiness assumption for non-iterable arguments in tuple/list/set calls (`SIM222`, `SIM223`) (#21479)
## Summary

Fixes false positives in SIM222 and SIM223 where truthiness was
incorrectly assumed for `tuple(x)`, `list(x)`, `set(x)` when `x` is not
iterable.

Fixes #21473.

## Problem

`Truthiness::from_expr` recursively called itself on arguments to
iterable initializers (`tuple`, `list`, `set`) without checking if the
argument is iterable, causing false positives for cases like `tuple(0)
or True` and `tuple("") or True`.

## Approach

Added `is_definitely_not_iterable` helper and updated
`Truthiness::from_expr` to return `Unknown` for non-iterable arguments
(numbers, booleans, None) and string literals when called with iterable
initializers, preventing incorrect truthiness assumptions.

## Test Plan

Added test cases to `SIM222.py` and `SIM223.py` for `tuple("")`,
`tuple(0)`, `tuple(1)`, `tuple(False)`, and `tuple(None)` with `or True`
and `and False` patterns.

---------

Co-authored-by: Brent Westbrook <brentrwestbrook@gmail.com>
2025-12-01 16:57:51 -05:00
..
SIM101.py Redirect `PLR1701` to `SIM101` (#12021) 2024-06-27 13:44:11 +02:00
SIM102.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
SIM103.py [`flake8-simplify`] Avoid double negations (`SIM103`) (#15562) 2025-01-18 17:06:46 +00:00
SIM105_0.py [`flake8-simplify`] Preserve original behavior for `except ()` and bare `except` (`SIM105`) (#18213) 2025-06-23 10:01:57 -04:00
SIM105_1.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
SIM105_2.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
SIM105_3.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
SIM105_4.py Skip BOM when inserting start-of-file imports (#7622) 2023-09-23 19:36:50 +00:00
SIM107.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
SIM108.py Preserve quotes in generated f-strings (#15794) 2025-01-29 13:28:22 -05:00
SIM109.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
SIM110.py Fix SIM110 with a yield in the condition (#7801) 2023-10-04 08:59:19 -04:00
SIM111.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
SIM112.py [`SIM112`] Ignore `https_proxy`, `http_proxy`, and `no_proxy` (#8140) 2023-10-23 08:48:36 -05:00
SIM113.py [`flake8-simplify`] Apply `SIM113` when index variable is of type `int` (#21395) 2025-11-12 17:54:39 +00:00
SIM114.py Parenthesize conditions based on precedence when merging if arms (#12737) 2024-08-07 23:03:24 -04:00
SIM115.py Fix F701 to F707 errors in tests (#19125) 2025-07-04 13:43:18 -05:00
SIM116.py Fix F701 to F707 errors in tests (#19125) 2025-07-04 13:43:18 -05:00
SIM117.py Fix typos found by codespell (#9346) 2024-01-02 02:08:15 +00:00
SIM118.py Improve inference capabilities of the `BuiltinTypeChecker` (#10976) 2024-04-16 18:53:22 +01:00
SIM201.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
SIM202.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
SIM208.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
SIM210.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
SIM211.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
SIM212.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
SIM220.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
SIM221.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
SIM222.py [`flake8-simplify`] Fix truthiness assumption for non-iterable arguments in tuple/list/set calls (`SIM222`, `SIM223`) (#21479) 2025-12-01 16:57:51 -05:00
SIM223.py [`flake8-simplify`] Fix truthiness assumption for non-iterable arguments in tuple/list/set calls (`SIM222`, `SIM223`) (#21479) 2025-12-01 16:57:51 -05:00
SIM300.py [`flake8-simplify`] More precise inference for dictionaries (`SIM300`) (#15164) 2024-12-30 10:41:33 +00:00
SIM401.py [flake8-simplify] Only trigger SIM401 on known dictionaries (SIM401) (#15995) 2025-02-07 08:25:20 +00:00
SIM905.py [`flake8-simplify`] Fix incorrect fix for positive `maxsplit` without separator (`SIM905`) (#20056) 2025-09-18 20:56:34 +00:00
SIM910.py [`flake8-simplify`] Detect unnecessary `None` default for additional key expression types (`SIM910`) (#20343) 2025-09-12 10:17:54 -04:00
SIM911.py [`flake8-simplify`] Skip `SIM911` when unknown arguments are present (#20697) 2025-10-21 16:58:48 -04:00