Skip to content

Commit 6f49dba

Browse files
committed
feat: add ruff rules
1 parent 51a7307 commit 6f49dba

65 files changed

Lines changed: 134 additions & 121 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pyproject.toml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,23 @@ select = [
1313
"B", # flake8-bugbear
1414
"C4", # flake8-comprehensions
1515
"UP", # pyupgrade
16+
"RUF", # ruff rules
17+
"C90", # mccabe
18+
"N", # pep8-naming
19+
"ASYNC", # flake8-async
20+
"C4", # flake8-comprehensions
21+
"T20", # flake8-print
22+
"SIM", # flake8-simplify
23+
"PT", # flake8-pytest-style
24+
"PTH", # flake8-puse-pathlib
25+
"TCH", # flake8-type-checking
26+
"PERF", # Perflint
1627
]
1728
ignore = [
18-
"E501", # line too long, handled by ruff
29+
"E501", # line too long, handled by formatter later
1930
"B008", # do not perform function calls in argument defaults
2031
"C901", # too complex
2132
"W191", # indentation contains tabs
33+
"RUF002", # docstring contains ambiguous letter
34+
"RUF003" # comment contains amgiuos letter
2235
]

src/g_prefix_sums/null_exchange.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ def null_exchange(a: list[int]) -> int:
1414
if curr_sum in p:
1515
count += p[curr_sum]
1616
# Добавляем текущую сумму в словарь или увеличиваем ее счетчик на один
17-
p[curr_sum] = (p[curr_sum] if curr_sum in p else 0) + 1
17+
p[curr_sum] = (p.get(curr_sum, 0)) + 1
1818
return count

src/h_number_theory/count_primes.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,4 @@ def count_primes_sieve(n: int) -> int:
2626
def is_prime_sqrt(n: int) -> bool:
2727
if n < 2:
2828
return False
29-
for i in range(2, int(n**0.5) + 1):
30-
if n % i == 0:
31-
return False
32-
return True
29+
return all(n % i != 0 for i in range(2, int(n**0.5) + 1))

src/h_number_theory/divisors.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ def divisors_naive(n: int) -> bool:
33
divisors = []
44
for i in range(1, n + 1):
55
if n % i == 0:
6-
divisors.append(i)
6+
divisors.append(i) # noqa: PERF401
77
return len(divisors) == 3
88

99

@@ -22,10 +22,7 @@ def divisors_sqrt(n: int) -> bool:
2222
def closest_divisors(n: int) -> list[int]:
2323
closest1 = two_closest(n + 1)
2424
closest2 = two_closest(n + 2)
25-
if closest1[1] - closest1[0] < closest2[1] - closest2[0]:
26-
result = closest1
27-
else:
28-
result = closest2
25+
result = closest1 if closest1[1] - closest1[0] < closest2[1] - closest2[0] else closest2
2926
return result
3027

3128

src/j_greedy/convex_hull.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ def convex_hull(points: list[tuple[int, int]]) -> list[tuple[int, int]]:
2020
# Учитываем коллинеарные точки - добавляем их в оболочку
2121
# Коллинеарные точки - это точки, лежащие на одной прямой с точками point и q
2222
for r in range(n):
23-
if r != point and r != q and orientation(points[point], points[q], points[r]) == 0:
24-
if on_segment(points[point], points[r], points[q]):
25-
if points[r] not in visited:
26-
hull.append(points[r])
27-
visited.add(points[r])
23+
if (
24+
r != point
25+
and r != q
26+
and orientation(points[point], points[q], points[r]) == 0
27+
and on_segment(points[point], points[r], points[q])
28+
and points[r] not in visited
29+
):
30+
hull.append(points[r])
31+
visited.add(points[r])
2832
# Переходим к следующей точке
2933
point = q
3034
if point == left:
@@ -35,11 +39,12 @@ def convex_hull(points: list[tuple[int, int]]) -> list[tuple[int, int]]:
3539
def left_index(points: list[tuple[int, int]]) -> int:
3640
left_most = 0
3741
for i in range(1, len(points)):
38-
if points[i][0] < points[left_most][0]:
42+
if (
43+
points[i][0] < points[left_most][0]
44+
or points[i][0] == points[left_most][0]
45+
and points[i][1] > points[left_most][1]
46+
):
3947
left_most = i
40-
elif points[i][0] == points[left_most][0]:
41-
if points[i][1] > points[left_most][1]:
42-
left_most = i
4348
return left_most
4449

4550

src/j_greedy/huffman.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
e -> 01
3434
3535
encoded = "111111111111100100101101101000000000101010101"
36-
""" # noqa
36+
"""
3737

3838

3939
# O(n)

tests/test_base_ds/test_bank_queue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
@pytest.mark.parametrize(
7-
"n, clients, expected",
7+
("n", "clients", "expected"),
88
[
99
(2, [(1, 10), (2, 5), (3, 7)], 1.333333),
1010
(1, [(1, 1), (2, 1), (3, 1)], 0),

tests/test_base_ds/test_brackets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
@pytest.mark.parametrize(
7-
"s, expected",
7+
("s", "expected"),
88
[
99
("[]", None),
1010
("{}", None),

tests/test_base_ds/test_calculator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
@pytest.mark.parametrize(
12-
"expression, expected",
12+
("expression", "expected"),
1313
[
1414
# Базовый случай.
1515
("2+2", ["2", "+", "2"]),
@@ -30,7 +30,7 @@ def test_split_by_tokens(expression: str, expected: list[str]) -> None:
3030

3131

3232
@pytest.mark.parametrize(
33-
"expression, expected",
33+
("expression", "expected"),
3434
[
3535
# Тестовый случай 1: Простое выражение без скобок.
3636
("2 + 2", "2 2 +"),
@@ -47,7 +47,7 @@ def test_get_postfix_notation(expression: str, expected: str) -> None:
4747

4848

4949
@pytest.mark.parametrize(
50-
"expression, expected",
50+
("expression", "expected"),
5151
[
5252
# Тестовый случай 1: Простое выражение без скобок.
5353
("2 2 +", 4.0),
@@ -64,7 +64,7 @@ def test_evaluate_postfix(expression: str, expected: float) -> None:
6464

6565

6666
@pytest.mark.parametrize(
67-
"expression, expected",
67+
("expression", "expected"),
6868
[
6969
# Тест из условия задачи.
7070
("(1+2)*4+3", 15.0),

tests/test_base_ds/test_max_stack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
@pytest.mark.parametrize(
7-
"operations, expected",
7+
("operations", "expected"),
88
[
99
(
1010
[

0 commit comments

Comments
 (0)