Fix SIM222 and SIM223 false positives and auto-fix#4063
Fix SIM222 and SIM223 false positives and auto-fix#4063charliermarsh merged 10 commits intoastral-sh:mainfrom JonathanPlasse:fix-sim222-sim223-false-positive-with-truthy-expressions
Conversation
PR Check ResultsEcosystemℹ️ ecosystem check detected changes. (+0, -1, 0 error(s)) airflow (+0, -1)
- airflow/providers/apache/kafka/operators/consume.py:100:29: SIM222 [*] Use `True` instead of `... or True`BenchmarkLinuxWindows |
|
Yeah, I'd vote to extract that concept into |
...c/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM222_SIM222.py.snap
Outdated
Show resolved
Hide resolved
...c/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM223_SIM223.py.snap
Outdated
Show resolved
Hide resolved
|
I added For example: # Inside test `a` is simplified
bool(a or [1] or True or [2])
assert a or [1] or True or [2]
if (a or [1] or True or [2]) and (a or [1] or True or [2]):
pass
# Outside test `a` is not simplified
a or [1] or True or [2]
if (a or [1] or True or [2]) == (a or [1]):
pass
if f(a or [1] or True or [2]):
pass |
|
There is a false positive that has been fixed in self.max_messages = max_messages or True |
|
Should I split this PR? |
|
I think it would be helpful. What do you think we can carve out into separate PRs? |
|
Here is the list of possible PRs
I will rebase this PR on |
|
The rebase is done. |
|
I will document the rules as we diverge a lot from the behavior of |
|
I documented the rules and detect when |
|
You for your edits, it is much cleaner and clearer now. |
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [ruff](https://togithub.com/charliermarsh/ruff) | `^0.0.262` -> `^0.0.263` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>charliermarsh/ruff</summary> ### [`v0.0.263`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.263) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.262...v0.0.263) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed ##### Rules - \[`flake8-bugbear`] Add `pytest.raises(Exception)` support to B017 by [@​alanhdu](https://togithub.com/alanhdu) in [https://github.com/charliermarsh/ruff/pull/4052](https://togithub.com/charliermarsh/ruff/pull/4052) - \[`flake8-import-conventions`] Implement new rule `ICN003` to ban `from ... import ...` for selected modules by [@​edgarrmondragon](https://togithub.com/edgarrmondragon) in [https://github.com/charliermarsh/ruff/pull/4040](https://togithub.com/charliermarsh/ruff/pull/4040) - \[`pylint`] Implement PLE0302 `unexpected-special-method-signature` by [@​mccullocht](https://togithub.com/mccullocht) in [https://github.com/charliermarsh/ruff/pull/4075](https://togithub.com/charliermarsh/ruff/pull/4075) - \[`pep8-naming`] Ignore `N815` for `TypedDict` fields by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/4066](https://togithub.com/charliermarsh/ruff/pull/4066) ##### Bug Fixes - Avoid `PYI015` for valid default value without annotation by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [https://github.com/charliermarsh/ruff/pull/4043](https://togithub.com/charliermarsh/ruff/pull/4043) - Avoid infinite-propagation of inline comments when force-splitting imports by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4074](https://togithub.com/charliermarsh/ruff/pull/4074) - Fix SIM222 and SIM223 false positives and auto-fix by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/4063](https://togithub.com/charliermarsh/ruff/pull/4063) - Unify positional and keyword arguments when checking for missing arguments in docstring by [@​evanrittenhouse](https://togithub.com/evanrittenhouse) in [https://github.com/charliermarsh/ruff/pull/4067](https://togithub.com/charliermarsh/ruff/pull/4067) - Avoid `RUF008` if field annotation is immutable by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [https://github.com/charliermarsh/ruff/pull/4039](https://togithub.com/charliermarsh/ruff/pull/4039) - Increment priority should be (branch-local, global) by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [https://github.com/charliermarsh/ruff/pull/4070](https://togithub.com/charliermarsh/ruff/pull/4070) - Ignore `ClassVar` annotation for `RUF008`, `RUF009` by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [https://github.com/charliermarsh/ruff/pull/4081](https://togithub.com/charliermarsh/ruff/pull/4081) - Support --fix in watch mode by [@​evanrittenhouse](https://togithub.com/evanrittenhouse) in [https://github.com/charliermarsh/ruff/pull/4035](https://togithub.com/charliermarsh/ruff/pull/4035) #### New Contributors - [@​alanhdu](https://togithub.com/alanhdu) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4052](https://togithub.com/charliermarsh/ruff/pull/4052) - [@​pronoym99](https://togithub.com/pronoym99) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4055](https://togithub.com/charliermarsh/ruff/pull/4055) - [@​Secrus](https://togithub.com/Secrus) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4085](https://togithub.com/charliermarsh/ruff/pull/4085) - [@​madkinsz](https://togithub.com/madkinsz) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4084](https://togithub.com/charliermarsh/ruff/pull/4084) - [@​mccullocht](https://togithub.com/mccullocht) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4075](https://togithub.com/charliermarsh/ruff/pull/4075) **Full Changelog**: astral-sh/ruff@v0.0.262...v0.0.263 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/ixm-one/pytest-cmake-presets). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS41OC4yIiwidXBkYXRlZEluVmVyIjoiMzUuNTguMiJ9--> Signed-off-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [ruff](https://togithub.com/charliermarsh/ruff) | `==0.0.262` -> `==0.0.263` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>charliermarsh/ruff</summary> ### [`v0.0.263`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.263) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.262...v0.0.263) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed ##### Rules - \[`flake8-bugbear`] Add `pytest.raises(Exception)` support to B017 by [@​alanhdu](https://togithub.com/alanhdu) in [https://github.com/charliermarsh/ruff/pull/4052](https://togithub.com/charliermarsh/ruff/pull/4052) - \[`flake8-import-conventions`] Implement new rule `ICN003` to ban `from ... import ...` for selected modules by [@​edgarrmondragon](https://togithub.com/edgarrmondragon) in [https://github.com/charliermarsh/ruff/pull/4040](https://togithub.com/charliermarsh/ruff/pull/4040) - \[`pylint`] Implement PLE0302 `unexpected-special-method-signature` by [@​mccullocht](https://togithub.com/mccullocht) in [https://github.com/charliermarsh/ruff/pull/4075](https://togithub.com/charliermarsh/ruff/pull/4075) - \[`pep8-naming`] Ignore `N815` for `TypedDict` fields by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/4066](https://togithub.com/charliermarsh/ruff/pull/4066) ##### Bug Fixes - Avoid `PYI015` for valid default value without annotation by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [https://github.com/charliermarsh/ruff/pull/4043](https://togithub.com/charliermarsh/ruff/pull/4043) - Avoid infinite-propagation of inline comments when force-splitting imports by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4074](https://togithub.com/charliermarsh/ruff/pull/4074) - Fix SIM222 and SIM223 false positives and auto-fix by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/4063](https://togithub.com/charliermarsh/ruff/pull/4063) - Unify positional and keyword arguments when checking for missing arguments in docstring by [@​evanrittenhouse](https://togithub.com/evanrittenhouse) in [https://github.com/charliermarsh/ruff/pull/4067](https://togithub.com/charliermarsh/ruff/pull/4067) - Avoid `RUF008` if field annotation is immutable by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [https://github.com/charliermarsh/ruff/pull/4039](https://togithub.com/charliermarsh/ruff/pull/4039) - Increment priority should be (branch-local, global) by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [https://github.com/charliermarsh/ruff/pull/4070](https://togithub.com/charliermarsh/ruff/pull/4070) - Ignore `ClassVar` annotation for `RUF008`, `RUF009` by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [https://github.com/charliermarsh/ruff/pull/4081](https://togithub.com/charliermarsh/ruff/pull/4081) - Support --fix in watch mode by [@​evanrittenhouse](https://togithub.com/evanrittenhouse) in [https://github.com/charliermarsh/ruff/pull/4035](https://togithub.com/charliermarsh/ruff/pull/4035) #### New Contributors - [@​alanhdu](https://togithub.com/alanhdu) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4052](https://togithub.com/charliermarsh/ruff/pull/4052) - [@​pronoym99](https://togithub.com/pronoym99) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4055](https://togithub.com/charliermarsh/ruff/pull/4055) - [@​Secrus](https://togithub.com/Secrus) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4085](https://togithub.com/charliermarsh/ruff/pull/4085) - [@​madkinsz](https://togithub.com/madkinsz) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4084](https://togithub.com/charliermarsh/ruff/pull/4084) - [@​mccullocht](https://togithub.com/mccullocht) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4075](https://togithub.com/charliermarsh/ruff/pull/4075) **Full Changelog**: astral-sh/ruff@v0.0.262...v0.0.263 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/allenporter/flux-local). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS41OC4yIiwidXBkYXRlZEluVmVyIjoiMzUuNTguMiJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [ruff](https://togithub.com/charliermarsh/ruff) | `==0.0.262` -> `==0.0.263` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>charliermarsh/ruff</summary> ### [`v0.0.263`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.263) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.262...v0.0.263) <!-- Release notes generated using configuration in .github/release.yml at main --> ##### What's Changed ##### Rules - \[`flake8-bugbear`] Add `pytest.raises(Exception)` support to B017 by [@​alanhdu](https://togithub.com/alanhdu) in [https://github.com/charliermarsh/ruff/pull/4052](https://togithub.com/charliermarsh/ruff/pull/4052) - \[`flake8-import-conventions`] Implement new rule `ICN003` to ban `from ... import ...` for selected modules by [@​edgarrmondragon](https://togithub.com/edgarrmondragon) in [https://github.com/charliermarsh/ruff/pull/4040](https://togithub.com/charliermarsh/ruff/pull/4040) - \[`pylint`] Implement PLE0302 `unexpected-special-method-signature` by [@​mccullocht](https://togithub.com/mccullocht) in [https://github.com/charliermarsh/ruff/pull/4075](https://togithub.com/charliermarsh/ruff/pull/4075) - \[`pep8-naming`] Ignore `N815` for `TypedDict` fields by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/4066](https://togithub.com/charliermarsh/ruff/pull/4066) ##### Bug Fixes - Avoid `PYI015` for valid default value without annotation by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [https://github.com/charliermarsh/ruff/pull/4043](https://togithub.com/charliermarsh/ruff/pull/4043) - Avoid infinite-propagation of inline comments when force-splitting imports by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/4074](https://togithub.com/charliermarsh/ruff/pull/4074) - Fix SIM222 and SIM223 false positives and auto-fix by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/4063](https://togithub.com/charliermarsh/ruff/pull/4063) - Unify positional and keyword arguments when checking for missing arguments in docstring by [@​evanrittenhouse](https://togithub.com/evanrittenhouse) in [https://github.com/charliermarsh/ruff/pull/4067](https://togithub.com/charliermarsh/ruff/pull/4067) - Avoid `RUF008` if field annotation is immutable by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [https://github.com/charliermarsh/ruff/pull/4039](https://togithub.com/charliermarsh/ruff/pull/4039) - Increment priority should be (branch-local, global) by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [https://github.com/charliermarsh/ruff/pull/4070](https://togithub.com/charliermarsh/ruff/pull/4070) - Ignore `ClassVar` annotation for `RUF008`, `RUF009` by [@​dhruvmanila](https://togithub.com/dhruvmanila) in [https://github.com/charliermarsh/ruff/pull/4081](https://togithub.com/charliermarsh/ruff/pull/4081) - Support --fix in watch mode by [@​evanrittenhouse](https://togithub.com/evanrittenhouse) in [https://github.com/charliermarsh/ruff/pull/4035](https://togithub.com/charliermarsh/ruff/pull/4035) ##### New Contributors - [@​alanhdu](https://togithub.com/alanhdu) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4052](https://togithub.com/charliermarsh/ruff/pull/4052) - [@​pronoym99](https://togithub.com/pronoym99) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4055](https://togithub.com/charliermarsh/ruff/pull/4055) - [@​Secrus](https://togithub.com/Secrus) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4085](https://togithub.com/charliermarsh/ruff/pull/4085) - [@​madkinsz](https://togithub.com/madkinsz) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4084](https://togithub.com/charliermarsh/ruff/pull/4084) - [@​mccullocht](https://togithub.com/mccullocht) made their first contribution in [https://github.com/charliermarsh/ruff/pull/4075](https://togithub.com/charliermarsh/ruff/pull/4075) **Full Changelog**: astral-sh/ruff@v0.0.262...v0.0.263 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/allenporter/pyrainbird). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS41OC4yIiwidXBkYXRlZEluVmVyIjoiMzUuNTguMiJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Special case truthy expressions like side-effect expressions.
If a truthy expression is followed by the short-circuiting boolean, remove the short-circuiting boolean too as it is unnecessary.
The violation message should be changed in this case to something like "remove everything after the truth expression".
I use
Truthinessfromflake8-bandit, butflake8-pytestalso hasis_falsy_constant().Should we make extract
Truthinessfromflake8-bandit, add the missing cases fromflake8-pytest, and use it forflake8-bandit,flake8-pytest, andflake8-simplify?I would be open making another PR for this.