Enable ruff RUF007 rule (#11349)

* Enable ruff RUF005 rule

* Enable ruff RUF007 rule

* Fix

* Fix

* Fix

* Update sorts/bead_sort.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update sorts/bead_sort.py

* Revert "Update sorts/bead_sort.py"

This reverts commit b10e5632e4.

* Revert "Update sorts/bead_sort.py"

This reverts commit 2c1816bf10.

* Update sorts/bead_sort.py

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
Maxim Smolskiy 2024-04-20 17:20:27 +03:00 committed by GitHub
parent 42593489d9
commit 7b88e15b1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 3 additions and 3 deletions

View File

@ -5,6 +5,7 @@ https://epaperpress.com/sortsearch/download/skiplist.pdf
from __future__ import annotations
from itertools import pairwise
from random import random
from typing import Generic, TypeVar
@ -389,7 +390,7 @@ def test_delete_doesnt_leave_dead_nodes():
def test_iter_always_yields_sorted_values():
def is_sorted(lst):
return all(next_item >= item for item, next_item in zip(lst, lst[1:]))
return all(next_item >= item for item, next_item in pairwise(lst))
skip_list = SkipList()
for i in range(10):

View File

@ -13,7 +13,6 @@ lint.ignore = [ # `ruff rule S101` for a description of that rule
"RUF001", # String contains ambiguous {}. Did you mean {}?
"RUF002", # Docstring contains ambiguous {}. Did you mean {}?
"RUF003", # Comment contains ambiguous {}. Did you mean {}?
"RUF007", # Prefer itertools.pairwise() over zip() when iterating over successive pairs
"S101", # Use of `assert` detected -- DO NOT FIX
"S113", # Probable use of requests call without timeout -- FIX ME
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes -- FIX ME

View File

@ -31,7 +31,7 @@ def bead_sort(sequence: list) -> list:
if any(not isinstance(x, int) or x < 0 for x in sequence):
raise TypeError("Sequence must be list of non-negative integers")
for _ in range(len(sequence)):
for i, (rod_upper, rod_lower) in enumerate(zip(sequence, sequence[1:])):
for i, (rod_upper, rod_lower) in enumerate(zip(sequence, sequence[1:])): # noqa: RUF007
if rod_upper > rod_lower:
sequence[i] -= rod_upper - rod_lower
sequence[i + 1] += rod_upper - rod_lower