Skip to content

Commit 53b2926

Browse files
Enable ruff PGH003 rule (TheAlgorithms#11345)
* Enable ruff PGH003 rule * Fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent f5bbea3 commit 53b2926

File tree

14 files changed

+20
-19
lines changed

14 files changed

+20
-19
lines changed

compression/huffman.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def build_tree(letters: list[Letter]) -> Letter | TreeNode:
4040
Run through the list of Letters and build the min heap
4141
for the Huffman Tree.
4242
"""
43-
response: list[Letter | TreeNode] = letters # type: ignore
43+
response: list[Letter | TreeNode] = list(letters)
4444
while len(response) > 1:
4545
left = response.pop(0)
4646
right = response.pop(0)
@@ -59,7 +59,7 @@ def traverse_tree(root: Letter | TreeNode, bitstring: str) -> list[Letter]:
5959
if isinstance(root, Letter):
6060
root.bitstring[root.letter] = bitstring
6161
return [root]
62-
treenode: TreeNode = root # type: ignore
62+
treenode: TreeNode = root
6363
letters = []
6464
letters += traverse_tree(treenode.left, bitstring + "0")
6565
letters += traverse_tree(treenode.right, bitstring + "1")

data_structures/binary_tree/binary_search_tree.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,9 @@ def remove(self, value: int) -> None:
294294
predecessor = self.get_max(
295295
node.left
296296
) # Gets the max value of the left branch
297-
self.remove(predecessor.value) # type: ignore
297+
self.remove(predecessor.value) # type: ignore[union-attr]
298298
node.value = (
299-
predecessor.value # type: ignore
299+
predecessor.value # type: ignore[union-attr]
300300
) # Assigns the value to the node to delete and keep tree structure
301301

302302
def preorder_traverse(self, node: Node | None) -> Iterable:

data_structures/linked_list/rotate_to_the_right.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def insert_node(head: Node | None, data: int) -> Node:
6363
while temp_node.next_node:
6464
temp_node = temp_node.next_node
6565

66-
temp_node.next_node = new_node # type: ignore
66+
temp_node.next_node = new_node
6767
return head
6868

6969

fractals/mandelbrot.py

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

1818
import colorsys
1919

20-
from PIL import Image # type: ignore
20+
from PIL import Image
2121

2222

2323
def get_distance(x: float, y: float, max_step: int) -> float:

graphics/bezier_curve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# https://www.tutorialspoint.com/computer_graphics/computer_graphics_curves.htm
33
from __future__ import annotations
44

5-
from scipy.special import comb # type: ignore
5+
from scipy.special import comb
66

77

88
class BezierCurve:

maths/entropy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ def analyze_text(text: str) -> tuple[dict, dict]:
9696
The first dictionary stores the frequency of single character strings.
9797
The second dictionary stores the frequency of two character strings.
9898
"""
99-
single_char_strings = Counter() # type: ignore
100-
two_char_strings = Counter() # type: ignore
99+
single_char_strings = Counter() # type: ignore[var-annotated]
100+
two_char_strings = Counter() # type: ignore[var-annotated]
101101
single_char_strings[text[-1]] += 1
102102

103103
# first case when we have space at start.

matrix/spiral_print.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ def spiral_traversal(matrix: list[list]) -> list[int]:
116116
[1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7] + spiral_traversal([])
117117
"""
118118
if matrix:
119-
return list(matrix.pop(0)) + spiral_traversal(list(zip(*matrix))[::-1]) # type: ignore
119+
return list(matrix.pop(0)) + spiral_traversal(
120+
[list(row) for row in zip(*matrix)][::-1]
121+
)
120122
else:
121123
return []
122124

matrix/tests/test_matrix_operation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import sys
1313

1414
import numpy as np
15-
import pytest # type: ignore
15+
import pytest
1616

1717
# Custom/local libraries
1818
from matrix import matrix_operation as matop

project_euler/problem_092/sol1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def chain(number: int) -> bool:
6868
"""
6969

7070
if CHAINS[number - 1] is not None:
71-
return CHAINS[number - 1] # type: ignore
71+
return CHAINS[number - 1] # type: ignore[return-value]
7272

7373
number_chain = chain(next_number(number))
7474
CHAINS[number - 1] = number_chain

project_euler/problem_104/sol1.py

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

1616
import sys
1717

18-
sys.set_int_max_str_digits(0) # type: ignore
18+
sys.set_int_max_str_digits(0)
1919

2020

2121
def check(number: int) -> bool:

0 commit comments

Comments
 (0)