diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 93e4d3d..7c18545 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ ci: skip: [mypy, pytest] repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.8 + rev: v0.9.4 hooks: - id: ruff args: [--fix] diff --git a/cs/algorithms/__init__.py b/cs/algorithms/__init__.py index 7ad0cf6..fe4100b 100644 --- a/cs/algorithms/__init__.py +++ b/cs/algorithms/__init__.py @@ -34,8 +34,8 @@ "breadth_first_search", "bubble_sort", "bucket_sort", - "build_suffix_array", "build_optimal_bst", + "build_suffix_array", "connected_components", "depth_first_search", "dfs_traversal", diff --git a/cs/algorithms/string/sais.py b/cs/algorithms/string/sais.py index 37be748..7943414 100644 --- a/cs/algorithms/string/sais.py +++ b/cs/algorithms/string/sais.py @@ -209,10 +209,8 @@ def get_suffix_annotations(text: list[int]) -> tuple[list[SuffixType], list[int] lms_suffixes: list[int] = [] suffix_marks = [SuffixType.S] * len(text) for k in range(len(text) - 1, 0, -1): - if ( - text[k - 1] > text[k] - or text[k - 1] == text[k] - and suffix_marks[k] is SuffixType.L + if text[k - 1] > text[k] or ( + text[k - 1] == text[k] and suffix_marks[k] is SuffixType.L ): suffix_marks[k - 1] = SuffixType.L if suffix_marks[k] is SuffixType.S: @@ -241,10 +239,8 @@ def to_rank_array(text: str) -> list[int]: def rank_text_to_str(char_map: dict[str, int], rank_text: list[int]) -> str: """Util function to convert rank text back into strings.""" result = "" - reversed_char_map = {} + reversed_char_map = {ch2: ch for ch, ch2 in char_map.items()} reversed_char_map[0] = "$" - for ch in char_map: - reversed_char_map[char_map[ch]] = ch for num in rank_text: result += reversed_char_map[num] return result diff --git a/cs/structures/__init__.py b/cs/structures/__init__.py index fbf2a6d..1391f12 100644 --- a/cs/structures/__init__.py +++ b/cs/structures/__init__.py @@ -29,6 +29,7 @@ from .trie import Trie __all__ = ( + "RMQ", "ApproxDistanceOracle", "ApproxFiniteMetricOracle", "BinaryHeap", @@ -53,7 +54,6 @@ "Node", "PrecomputedRMQ", "Queue", - "RMQ", "RedBlackTree", "RedBlackTreeNode", "RobinHood", diff --git a/cs/structures/heap/fibonacci_heap.py b/cs/structures/heap/fibonacci_heap.py index d82e8e5..fc02eaa 100644 --- a/cs/structures/heap/fibonacci_heap.py +++ b/cs/structures/heap/fibonacci_heap.py @@ -349,7 +349,7 @@ def dequeue(self) -> tuple[T, float]: # reparent operation that merged two different trees of equal # priority, we need to make sure that the min pointer points to # the root-level one. - if curr <= self.top: + if curr <= self.top: # noqa: PLR1730 self.top = curr if not self.allow_duplicates: del self.elem_to_entry[min_elem.value] diff --git a/cs/structures/queue.py b/cs/structures/queue.py index 5b2b151..85c85e4 100644 --- a/cs/structures/queue.py +++ b/cs/structures/queue.py @@ -1,3 +1,4 @@ +# noqa: A005 from dataclasses import dataclass, field from typing import Generic, TypeVar diff --git a/cs/structures/tree/red_black_tree.py b/cs/structures/tree/red_black_tree.py index 4bb751c..3061c0b 100644 --- a/cs/structures/tree/red_black_tree.py +++ b/cs/structures/tree/red_black_tree.py @@ -134,9 +134,11 @@ def _check_coloring(node: RedBlackTreeNode[T] | None) -> bool: """ return node is None or ( node.color is Color.BLACK - or self.color(node.left) is self.color(node.right) is Color.BLACK - and _check_coloring(node.left) - and _check_coloring(node.right) + or ( + self.color(node.left) is self.color(node.right) is Color.BLACK + and _check_coloring(node.left) + and _check_coloring(node.right) + ) ) def _black_height(node: RedBlackTreeNode[T] | None) -> int: diff --git a/explore/rmq.py b/explore/rmq.py index c01398a..2640717 100644 --- a/explore/rmq.py +++ b/explore/rmq.py @@ -20,7 +20,7 @@ def construct_rmq(rmq_type: str, data: list[int]) -> RMQ: def print_arr_with_index(data: list[int], low: int) -> str: result = f"\nIndex | Data\n{'-' * 15}\n" for i, value in enumerate(data): - result += f"{low+i if low else i:5d} | {value}\n" + result += f"{low + i if low else i:5d} | {value}\n" return result @@ -71,7 +71,7 @@ def run_tests(minimum: int, maximum: int, num_builds: int, num_queries: int) -> assert data[ours] == data[theirs], ( "Error: query produced the wrong answer:\n\n" f"Query: Low: {low}, High: {high}\n" - f"{print_arr_with_index(data[low: high], low)}\n" + f"{print_arr_with_index(data[low:high], low)}\n" f"Solution Index: {ours}, Your Index: {theirs}\n\n" f"Val at index {ours}: {data[ours]}, " f"Val at index {theirs}: {data[theirs]}" diff --git a/requirements-dev.txt b/requirements-dev.txt index 48a292d..e26e528 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -45,7 +45,7 @@ pytest-deadfixtures==2.2.1 pytest-idempotent==1.3.1 pytest-timeout==2.3.1 pyupgrade==3.17.0 -ruff==0.6.8 +ruff==0.9.4 scalene==1.5.44.1 sort-requirements==1.3.0 twine==5.1.1 diff --git a/ruff.toml b/ruff.toml index 6cba06b..1418075 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,8 +1,6 @@ target-version = "py312" lint.select = ["ALL"] lint.ignore = [ - "ANN101", # Missing type annotation for `self` in method - "ANN102", # Missing type annotation for `cls` in classmethod "ANN401", # Dynamically typed expressions (typing.Any) are disallowed "C901", # function is too complex (12 > 10) "COM812", # Trailing comma missing diff --git a/tests/structures/hash_table/hash_table_test.py b/tests/structures/hash_table/hash_table_test.py index 5cd4fe0..e05286e 100644 --- a/tests/structures/hash_table/hash_table_test.py +++ b/tests/structures/hash_table/hash_table_test.py @@ -12,7 +12,7 @@ T = TypeVar("T", bound=Comparable) parametrize_hash_table_type = pytest.mark.parametrize( - "hash_table_type", ("Cuckoo", "LinearProbing", "RobinHood") + "hash_table_type", ["Cuckoo", "LinearProbing", "RobinHood"] ) diff --git a/tests/structures/heap/heap_test.py b/tests/structures/heap/heap_test.py index 9c933a4..5a7f60c 100644 --- a/tests/structures/heap/heap_test.py +++ b/tests/structures/heap/heap_test.py @@ -10,10 +10,10 @@ T = TypeVar("T", bound=Comparable) parametrize_heap_type = pytest.mark.parametrize( - "heap_type", ("BinomialHeap", "FibonacciHeap") + "heap_type", ["BinomialHeap", "FibonacciHeap"] ) parametrize_allow_duplicates = pytest.mark.parametrize( - "allow_duplicates", (True, False) + "allow_duplicates", [True, False] ) diff --git a/tests/structures/rmq_test.py b/tests/structures/rmq_test.py index 4b73b83..25e2187 100644 --- a/tests/structures/rmq_test.py +++ b/tests/structures/rmq_test.py @@ -5,7 +5,7 @@ from cs.structures import RMQ, FischerHeunRMQ, HybridRMQ, PrecomputedRMQ, SparseTableRMQ parametrize_rmq_type = pytest.mark.parametrize( - "rmq_type", ("FischerHeunRMQ", "HybridRMQ", "PrecomputedRMQ", "SparseTableRMQ") + "rmq_type", ["FischerHeunRMQ", "HybridRMQ", "PrecomputedRMQ", "SparseTableRMQ"] ) diff --git a/tests/structures/tree/tree_test.py b/tests/structures/tree/tree_test.py index b82de5b..b1c5db6 100644 --- a/tests/structures/tree/tree_test.py +++ b/tests/structures/tree/tree_test.py @@ -10,7 +10,7 @@ T = TypeVar("T", bound=Comparable) parametrize_tree_types = pytest.mark.parametrize( - "tree_type", ("BinarySearchTree", "RedBlackTree") + "tree_type", ["BinarySearchTree", "RedBlackTree"] ) TEN_ELEMS = (8, 3, 6, 1, 10, 14, 13, 4, 7, 5) diff --git a/utils/ruff_ignore.py b/utils/ruff_ignore.py index 2a7eea8..b2b3e8f 100644 --- a/utils/ruff_ignore.py +++ b/utils/ruff_ignore.py @@ -23,7 +23,7 @@ def main() -> None: error_messages[error_code] = error_message for error_code, error_message in sorted(error_messages.items()): spaces = 8 - len(error_code) - print(f'"{error_code}",{' ' * spaces}# {error_message}') + print(f'"{error_code}",{" " * spaces}# {error_message}') def extract_details(ruff_error_line: str) -> tuple[Path, int, int, str]: