From ce75a040213ae2c5e4eed5b25f120c9dfb300954 Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Tue, 2 Apr 2024 20:07:33 +0300 Subject: [PATCH] Enable ruff RUF007 rule --- data_structures/linked_list/skip_list.py | 3 ++- pyproject.toml | 1 - sorts/bead_sort.py | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/data_structures/linked_list/skip_list.py b/data_structures/linked_list/skip_list.py index 88d3e0dad..13e9a94a8 100644 --- a/data_structures/linked_list/skip_list.py +++ b/data_structures/linked_list/skip_list.py @@ -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): diff --git a/pyproject.toml b/pyproject.toml index 3a012203a..e82f43e3d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,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 diff --git a/sorts/bead_sort.py b/sorts/bead_sort.py index e51173643..51133f7a2 100644 --- a/sorts/bead_sort.py +++ b/sorts/bead_sort.py @@ -3,6 +3,8 @@ Bead sort only works for sequences of non-negative integers. https://en.wikipedia.org/wiki/Bead_sort """ +from itertools import pairwise + def bead_sort(sequence: list) -> list: """ @@ -31,7 +33,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(pairwise(sequence)): if rod_upper > rod_lower: sequence[i] -= rod_upper - rod_lower sequence[i + 1] += rod_upper - rod_lower