Skip to content

Commit

Permalink
Upgrade to Ruff v0.9.4
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerYep committed Feb 2, 2025
1 parent 76d5ad5 commit 5a6e47a
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion cs/algorithms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 3 additions & 7 deletions cs/algorithms/string/sais.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion cs/structures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from .trie import Trie

__all__ = (
"RMQ",
"ApproxDistanceOracle",
"ApproxFiniteMetricOracle",
"BinaryHeap",
Expand All @@ -53,7 +54,6 @@
"Node",
"PrecomputedRMQ",
"Queue",
"RMQ",
"RedBlackTree",
"RedBlackTreeNode",
"RobinHood",
Expand Down
2 changes: 1 addition & 1 deletion cs/structures/heap/fibonacci_heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions cs/structures/queue.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# noqa: A005
from dataclasses import dataclass, field
from typing import Generic, TypeVar

Expand Down
8 changes: 5 additions & 3 deletions cs/structures/tree/red_black_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions explore/rmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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]}"
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/structures/hash_table/hash_table_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)


Expand Down
4 changes: 2 additions & 2 deletions tests/structures/heap/heap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)


Expand Down
2 changes: 1 addition & 1 deletion tests/structures/rmq_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)


Expand Down
2 changes: 1 addition & 1 deletion tests/structures/tree/tree_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion utils/ruff_ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down

0 comments on commit 5a6e47a

Please sign in to comment.