Prefer itertools.pairwise() over zip() for successive pairs (RUF007)#3501
Merged
charliermarsh merged 12 commits intoastral-sh:mainfrom Mar 17, 2023
Merged
Conversation
andersk
reviewed
Mar 14, 2023
Contributor
andersk
left a comment
There was a problem hiding this comment.
itertools.pairwise is new in Python 3.10, so this rule should be restricted to target_version >= PyVersion::Py310.
Should we also check for zip(a[:-1], a[1:])?
980b098 to
e6c51af
Compare
Contributor
|
✅ ecosystem check detected no changes. |
MichaReiser
reviewed
Mar 15, 2023
andersk
reviewed
Mar 15, 2023
andersk
reviewed
Mar 15, 2023
MichaReiser
approved these changes
Mar 16, 2023
63001bc to
9a38f44
Compare
Also have to change this commit message and finish the stuf laid out in CONTRIBUTING.md
9a38f44 to
9e9e8fb
Compare
Contributor
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinuxWindows |
Member
|
Should have time to merge this tonight if it's in good shape! |
Contributor
Author
|
@charliermarsh just have to get the new changes re-reviewed - I changed the logic for determining successive pairs to simply be a difference of 1 between start of first/second slices. That'll allow us to pick up cases like |
itertools.pairwise() over zip() for successive pairsitertools.pairwise() over zip() for successive pairs (RUF007)
Member
|
Thanks @evanrittenhouse! |
renovate bot
referenced
this pull request
in ixm-one/pytest-cmake-presets
Mar 18, 2023
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [ruff](https://togithub.com/charliermarsh/ruff) | `^0.0.256` -> `^0.0.257` | [](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.257`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.257) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.256...v0.0.257) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed ##### Rules - \[`ruff`] Prefer `itertools.pairwise()` over `zip()` for successive pairs (`RUF007`) by [@​evanrittenhouse](https://togithub.com/evanrittenhouse) in [https://github.com/charliermarsh/ruff/pull/3501](https://togithub.com/charliermarsh/ruff/pull/3501) - \[`flake8-bugbear`] Add `no-explicit-stacklevel` (`B028`) by [@​johnor](https://togithub.com/johnor) in [https://github.com/charliermarsh/ruff/pull/3550](https://togithub.com/charliermarsh/ruff/pull/3550) - \[`pylint`] invalid-characters-\* by [@​r3m0t](https://togithub.com/r3m0t) in [https://github.com/charliermarsh/ruff/pull/3552](https://togithub.com/charliermarsh/ruff/pull/3552) - \[`pylint`] Implement `useless-return` (`R1711`) by [@​tomecki](https://togithub.com/tomecki) in [https://github.com/charliermarsh/ruff/pull/3116](https://togithub.com/charliermarsh/ruff/pull/3116) - \[`pylint`]: Implement `continue-in-finally` (`E0116`) by [@​latonis](https://togithub.com/latonis) in [https://github.com/charliermarsh/ruff/pull/3541](https://togithub.com/charliermarsh/ruff/pull/3541) ##### Bug Fixes - Rewrite mock import with starred imports by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3566](https://togithub.com/charliermarsh/ruff/pull/3566) - Respect `type` overrides in E721 by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3582](https://togithub.com/charliermarsh/ruff/pull/3582) - Use `value > max` style in pylint and mccabe messages by [@​edgarrmondragon](https://togithub.com/edgarrmondragon) in [https://github.com/charliermarsh/ruff/pull/3553](https://togithub.com/charliermarsh/ruff/pull/3553) - Fix autofix conflict between `D209` and `D400` by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/3564](https://togithub.com/charliermarsh/ruff/pull/3564) - Avoid C1901 violations within subscripts by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3517](https://togithub.com/charliermarsh/ruff/pull/3517) - Avoid adding dashed line outside of docstring by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3581](https://togithub.com/charliermarsh/ruff/pull/3581) - Enable ANSI colors on Windows 10 by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3583](https://togithub.com/charliermarsh/ruff/pull/3583) #### New Contributors - [@​johnor](https://togithub.com/johnor) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3550](https://togithub.com/charliermarsh/ruff/pull/3550) **Full Changelog**: astral-sh/ruff@v0.0.256...v0.0.257 </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:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMC4yIiwidXBkYXRlZEluVmVyIjoiMzUuMTAuMiJ9--> Signed-off-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
renovate bot
referenced
this pull request
in allenporter/flux-local
Mar 21, 2023
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [ruff](https://togithub.com/charliermarsh/ruff) | `==0.0.256` -> `==0.0.257` | [](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.257`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.257) [Compare Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.256...v0.0.257) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed ##### Rules - \[`ruff`] Prefer `itertools.pairwise()` over `zip()` for successive pairs (`RUF007`) by [@​evanrittenhouse](https://togithub.com/evanrittenhouse) in [https://github.com/charliermarsh/ruff/pull/3501](https://togithub.com/charliermarsh/ruff/pull/3501) - \[`flake8-bugbear`] Add `no-explicit-stacklevel` (`B028`) by [@​johnor](https://togithub.com/johnor) in [https://github.com/charliermarsh/ruff/pull/3550](https://togithub.com/charliermarsh/ruff/pull/3550) - \[`pylint`] invalid-characters-\* by [@​r3m0t](https://togithub.com/r3m0t) in [https://github.com/charliermarsh/ruff/pull/3552](https://togithub.com/charliermarsh/ruff/pull/3552) - \[`pylint`] Implement `useless-return` (`R1711`) by [@​tomecki](https://togithub.com/tomecki) in [https://github.com/charliermarsh/ruff/pull/3116](https://togithub.com/charliermarsh/ruff/pull/3116) - \[`pylint`]: Implement `continue-in-finally` (`E0116`) by [@​latonis](https://togithub.com/latonis) in [https://github.com/charliermarsh/ruff/pull/3541](https://togithub.com/charliermarsh/ruff/pull/3541) ##### Bug Fixes - Rewrite mock import with starred imports by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3566](https://togithub.com/charliermarsh/ruff/pull/3566) - Respect `type` overrides in E721 by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3582](https://togithub.com/charliermarsh/ruff/pull/3582) - Use `value > max` style in pylint and mccabe messages by [@​edgarrmondragon](https://togithub.com/edgarrmondragon) in [https://github.com/charliermarsh/ruff/pull/3553](https://togithub.com/charliermarsh/ruff/pull/3553) - Fix autofix conflict between `D209` and `D400` by [@​JonathanPlasse](https://togithub.com/JonathanPlasse) in [https://github.com/charliermarsh/ruff/pull/3564](https://togithub.com/charliermarsh/ruff/pull/3564) - Avoid C1901 violations within subscripts by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3517](https://togithub.com/charliermarsh/ruff/pull/3517) - Avoid adding dashed line outside of docstring by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3581](https://togithub.com/charliermarsh/ruff/pull/3581) - Enable ANSI colors on Windows 10 by [@​charliermarsh](https://togithub.com/charliermarsh) in [https://github.com/charliermarsh/ruff/pull/3583](https://togithub.com/charliermarsh/ruff/pull/3583) #### New Contributors - [@​johnor](https://togithub.com/johnor) made their first contribution in [https://github.com/charliermarsh/ruff/pull/3550](https://togithub.com/charliermarsh/ruff/pull/3550) **Full Changelog**: astral-sh/ruff@v0.0.256...v0.0.257 </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:eyJjcmVhdGVkSW5WZXIiOiIzNS4xNC4yIiwidXBkYXRlZEluVmVyIjoiMzUuMTQuMiJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3297.
We ensure that the two arguments to
zip()match and that the lower bound of the slice is 1, if the second argument is a slice. Otherwise, we wouldn't be able to guarantee that the request being made is for successive pairs.