-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix SIM222 and SIM223 false positives and auto-fix #4063
Fix SIM222 and SIM223 false positives and auto-fix #4063
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` BenchmarkLinux
Windows
|
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
5aae7b0
to
c53a4f8
Compare
6494f49
to
61efc2e
Compare
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 |
d5777b6
to
8d431fb
Compare
There is a false positive that has been fixed in self.max_messages = max_messages or True |
fcaf7c5
to
ec92f6d
Compare
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 |
31c56c4
to
2178479
Compare
2178479
to
fd084bf
Compare
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. |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [ruff](https://github.com/charliermarsh/ruff) | `^0.0.262` -> `^0.0.263` | [![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/compatibility-slim/0.0.262)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/confidence-slim/0.0.262)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>charliermarsh/ruff</summary> ### [`v0.0.263`](https://github.com/charliermarsh/ruff/releases/tag/v0.0.263) [Compare Source](https://github.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://github.com/alanhdu) in [astral-sh/ruff#4052 - \[`flake8-import-conventions`] Implement new rule `ICN003` to ban `from ... import ...` for selected modules by [@​edgarrmondragon](https://github.com/edgarrmondragon) in [astral-sh/ruff#4040 - \[`pylint`] Implement PLE0302 `unexpected-special-method-signature` by [@​mccullocht](https://github.com/mccullocht) in [astral-sh/ruff#4075 - \[`pep8-naming`] Ignore `N815` for `TypedDict` fields by [@​JonathanPlasse](https://github.com/JonathanPlasse) in [astral-sh/ruff#4066 ##### Bug Fixes - Avoid `PYI015` for valid default value without annotation by [@​dhruvmanila](https://github.com/dhruvmanila) in [astral-sh/ruff#4043 - Avoid infinite-propagation of inline comments when force-splitting imports by [@​charliermarsh](https://github.com/charliermarsh) in [astral-sh/ruff#4074 - Fix SIM222 and SIM223 false positives and auto-fix by [@​JonathanPlasse](https://github.com/JonathanPlasse) in [astral-sh/ruff#4063 - Unify positional and keyword arguments when checking for missing arguments in docstring by [@​evanrittenhouse](https://github.com/evanrittenhouse) in [astral-sh/ruff#4067 - Avoid `RUF008` if field annotation is immutable by [@​dhruvmanila](https://github.com/dhruvmanila) in [astral-sh/ruff#4039 - Increment priority should be (branch-local, global) by [@​dhruvmanila](https://github.com/dhruvmanila) in [astral-sh/ruff#4070 - Ignore `ClassVar` annotation for `RUF008`, `RUF009` by [@​dhruvmanila](https://github.com/dhruvmanila) in [astral-sh/ruff#4081 - Support --fix in watch mode by [@​evanrittenhouse](https://github.com/evanrittenhouse) in [astral-sh/ruff#4035 #### New Contributors - [@​alanhdu](https://github.com/alanhdu) made their first contribution in [astral-sh/ruff#4052 - [@​pronoym99](https://github.com/pronoym99) made their first contribution in [astral-sh/ruff#4055 - [@​Secrus](https://github.com/Secrus) made their first contribution in [astral-sh/ruff#4085 - [@​madkinsz](https://github.com/madkinsz) made their first contribution in [astral-sh/ruff#4084 - [@​mccullocht](https://github.com/mccullocht) made their first contribution in [astral-sh/ruff#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>
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [ruff](https://github.com/charliermarsh/ruff) | `==0.0.262` -> `==0.0.263` | [![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/compatibility-slim/0.0.262)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/confidence-slim/0.0.262)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>charliermarsh/ruff</summary> ### [`v0.0.263`](https://github.com/charliermarsh/ruff/releases/tag/v0.0.263) [Compare Source](https://github.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://github.com/alanhdu) in [astral-sh/ruff#4052 - \[`flake8-import-conventions`] Implement new rule `ICN003` to ban `from ... import ...` for selected modules by [@​edgarrmondragon](https://github.com/edgarrmondragon) in [astral-sh/ruff#4040 - \[`pylint`] Implement PLE0302 `unexpected-special-method-signature` by [@​mccullocht](https://github.com/mccullocht) in [astral-sh/ruff#4075 - \[`pep8-naming`] Ignore `N815` for `TypedDict` fields by [@​JonathanPlasse](https://github.com/JonathanPlasse) in [astral-sh/ruff#4066 ##### Bug Fixes - Avoid `PYI015` for valid default value without annotation by [@​dhruvmanila](https://github.com/dhruvmanila) in [astral-sh/ruff#4043 - Avoid infinite-propagation of inline comments when force-splitting imports by [@​charliermarsh](https://github.com/charliermarsh) in [astral-sh/ruff#4074 - Fix SIM222 and SIM223 false positives and auto-fix by [@​JonathanPlasse](https://github.com/JonathanPlasse) in [astral-sh/ruff#4063 - Unify positional and keyword arguments when checking for missing arguments in docstring by [@​evanrittenhouse](https://github.com/evanrittenhouse) in [astral-sh/ruff#4067 - Avoid `RUF008` if field annotation is immutable by [@​dhruvmanila](https://github.com/dhruvmanila) in [astral-sh/ruff#4039 - Increment priority should be (branch-local, global) by [@​dhruvmanila](https://github.com/dhruvmanila) in [astral-sh/ruff#4070 - Ignore `ClassVar` annotation for `RUF008`, `RUF009` by [@​dhruvmanila](https://github.com/dhruvmanila) in [astral-sh/ruff#4081 - Support --fix in watch mode by [@​evanrittenhouse](https://github.com/evanrittenhouse) in [astral-sh/ruff#4035 #### New Contributors - [@​alanhdu](https://github.com/alanhdu) made their first contribution in [astral-sh/ruff#4052 - [@​pronoym99](https://github.com/pronoym99) made their first contribution in [astral-sh/ruff#4055 - [@​Secrus](https://github.com/Secrus) made their first contribution in [astral-sh/ruff#4085 - [@​madkinsz](https://github.com/madkinsz) made their first contribution in [astral-sh/ruff#4084 - [@​mccullocht](https://github.com/mccullocht) made their first contribution in [astral-sh/ruff#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>
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [ruff](https://github.com/charliermarsh/ruff) | `==0.0.262` -> `==0.0.263` | [![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/compatibility-slim/0.0.262)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.263/confidence-slim/0.0.262)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>charliermarsh/ruff</summary> ### [`v0.0.263`](https://github.com/charliermarsh/ruff/releases/tag/v0.0.263) [Compare Source](https://github.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://github.com/alanhdu) in [astral-sh/ruff#4052 - \[`flake8-import-conventions`] Implement new rule `ICN003` to ban `from ... import ...` for selected modules by [@​edgarrmondragon](https://github.com/edgarrmondragon) in [astral-sh/ruff#4040 - \[`pylint`] Implement PLE0302 `unexpected-special-method-signature` by [@​mccullocht](https://github.com/mccullocht) in [astral-sh/ruff#4075 - \[`pep8-naming`] Ignore `N815` for `TypedDict` fields by [@​JonathanPlasse](https://github.com/JonathanPlasse) in [astral-sh/ruff#4066 ##### Bug Fixes - Avoid `PYI015` for valid default value without annotation by [@​dhruvmanila](https://github.com/dhruvmanila) in [astral-sh/ruff#4043 - Avoid infinite-propagation of inline comments when force-splitting imports by [@​charliermarsh](https://github.com/charliermarsh) in [astral-sh/ruff#4074 - Fix SIM222 and SIM223 false positives and auto-fix by [@​JonathanPlasse](https://github.com/JonathanPlasse) in [astral-sh/ruff#4063 - Unify positional and keyword arguments when checking for missing arguments in docstring by [@​evanrittenhouse](https://github.com/evanrittenhouse) in [astral-sh/ruff#4067 - Avoid `RUF008` if field annotation is immutable by [@​dhruvmanila](https://github.com/dhruvmanila) in [astral-sh/ruff#4039 - Increment priority should be (branch-local, global) by [@​dhruvmanila](https://github.com/dhruvmanila) in [astral-sh/ruff#4070 - Ignore `ClassVar` annotation for `RUF008`, `RUF009` by [@​dhruvmanila](https://github.com/dhruvmanila) in [astral-sh/ruff#4081 - Support --fix in watch mode by [@​evanrittenhouse](https://github.com/evanrittenhouse) in [astral-sh/ruff#4035 ##### New Contributors - [@​alanhdu](https://github.com/alanhdu) made their first contribution in [astral-sh/ruff#4052 - [@​pronoym99](https://github.com/pronoym99) made their first contribution in [astral-sh/ruff#4055 - [@​Secrus](https://github.com/Secrus) made their first contribution in [astral-sh/ruff#4085 - [@​madkinsz](https://github.com/madkinsz) made their first contribution in [astral-sh/ruff#4084 - [@​mccullocht](https://github.com/mccullocht) made their first contribution in [astral-sh/ruff#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
Truthiness
fromflake8-bandit
, butflake8-pytest
also hasis_falsy_constant()
.Should we make extract
Truthiness
fromflake8-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.