Skip to content

Commit d5a9f64

Browse files
CaedenPHcclausspre-commit-ci[bot]dhruvmanila
authored
Add flake8-builtins to pre-commit and fix errors (TheAlgorithms#7105)
Ignore `A003` Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
1 parent e661b98 commit d5a9f64

31 files changed

+113
-106
lines changed

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
extend-ignore =
3+
A003 # Class attribute is shadowing a python builtin

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ repos:
4040
- --ignore=E203,W503
4141
- --max-complexity=25
4242
- --max-line-length=88
43-
additional_dependencies: [pep8-naming]
43+
additional_dependencies: [flake8-builtins, pep8-naming]
4444

4545
- repo: https://github.com/pre-commit/mirrors-mypy
4646
rev: v0.982

arithmetic_analysis/gaussian_elimination.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ def retroactive_resolution(
3333

3434
x: NDArray[float64] = np.zeros((rows, 1), dtype=float)
3535
for row in reversed(range(rows)):
36-
sum = 0
36+
total = 0
3737
for col in range(row + 1, columns):
38-
sum += coefficients[row, col] * x[col]
38+
total += coefficients[row, col] * x[col]
3939

40-
x[row, 0] = (vector[row] - sum) / coefficients[row, row]
40+
x[row, 0] = (vector[row] - total) / coefficients[row, row]
4141

4242
return x
4343

arithmetic_analysis/jacobi_iteration_method.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ def strictly_diagonally_dominant(table: NDArray[float64]) -> bool:
147147
is_diagonally_dominant = True
148148

149149
for i in range(0, rows):
150-
sum = 0
150+
total = 0
151151
for j in range(0, cols - 1):
152152
if i == j:
153153
continue
154154
else:
155-
sum += table[i][j]
155+
total += table[i][j]
156156

157-
if table[i][i] <= sum:
157+
if table[i][i] <= total:
158158
raise ValueError("Coefficient matrix is not strictly diagonally dominant")
159159

160160
return is_diagonally_dominant

audio_filters/show_response.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_bounds(
3434
return lowest, highest
3535

3636

37-
def show_frequency_response(filter: FilterType, samplerate: int) -> None:
37+
def show_frequency_response(filter_type: FilterType, samplerate: int) -> None:
3838
"""
3939
Show frequency response of a filter
4040
@@ -45,7 +45,7 @@ def show_frequency_response(filter: FilterType, samplerate: int) -> None:
4545

4646
size = 512
4747
inputs = [1] + [0] * (size - 1)
48-
outputs = [filter.process(item) for item in inputs]
48+
outputs = [filter_type.process(item) for item in inputs]
4949

5050
filler = [0] * (samplerate - size) # zero-padding
5151
outputs += filler
@@ -66,7 +66,7 @@ def show_frequency_response(filter: FilterType, samplerate: int) -> None:
6666
plt.show()
6767

6868

69-
def show_phase_response(filter: FilterType, samplerate: int) -> None:
69+
def show_phase_response(filter_type: FilterType, samplerate: int) -> None:
7070
"""
7171
Show phase response of a filter
7272
@@ -77,7 +77,7 @@ def show_phase_response(filter: FilterType, samplerate: int) -> None:
7777

7878
size = 512
7979
inputs = [1] + [0] * (size - 1)
80-
outputs = [filter.process(item) for item in inputs]
80+
outputs = [filter_type.process(item) for item in inputs]
8181

8282
filler = [0] * (samplerate - size) # zero-padding
8383
outputs += filler

backtracking/hamiltonian_cycle.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ def util_hamilton_cycle(graph: list[list[int]], path: list[int], curr_ind: int)
9595
return graph[path[curr_ind - 1]][path[0]] == 1
9696

9797
# Recursive Step
98-
for next in range(0, len(graph)):
99-
if valid_connection(graph, next, curr_ind, path):
98+
for next_ver in range(0, len(graph)):
99+
if valid_connection(graph, next_ver, curr_ind, path):
100100
# Insert current vertex into path as next transition
101-
path[curr_ind] = next
101+
path[curr_ind] = next_ver
102102
# Validate created path
103103
if util_hamilton_cycle(graph, path, curr_ind + 1):
104104
return True

data_structures/binary_tree/avl_tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def pop(self) -> Any:
3333
def count(self) -> int:
3434
return self.tail - self.head
3535

36-
def print(self) -> None:
36+
def print_queue(self) -> None:
3737
print(self.data)
3838
print("**************")
3939
print(self.data[self.head : self.tail])

data_structures/linked_list/__init__.py

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

1212

1313
class Node:
14-
def __init__(self, item: Any, next: Any) -> None:
14+
def __init__(self, item: Any, next: Any) -> None: # noqa: A002
1515
self.item = item
1616
self.next = next
1717

data_structures/linked_list/singly_linked_list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def test_singly_linked_list_2() -> None:
392392
This section of the test used varying data types for input.
393393
>>> test_singly_linked_list_2()
394394
"""
395-
input = [
395+
test_input = [
396396
-9,
397397
100,
398398
Node(77345112),
@@ -410,7 +410,7 @@ def test_singly_linked_list_2() -> None:
410410
]
411411
linked_list = LinkedList()
412412

413-
for i in input:
413+
for i in test_input:
414414
linked_list.insert_tail(i)
415415

416416
# Check if it's empty or not

data_structures/queue/double_ended_queue.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class Deque:
1515
----------
1616
append(val: Any) -> None
1717
appendleft(val: Any) -> None
18-
extend(iter: Iterable) -> None
19-
extendleft(iter: Iterable) -> None
18+
extend(iterable: Iterable) -> None
19+
extendleft(iterable: Iterable) -> None
2020
pop() -> Any
2121
popleft() -> Any
2222
Observers
@@ -179,9 +179,9 @@ def appendleft(self, val: Any) -> None:
179179
# make sure there were no errors
180180
assert not self.is_empty(), "Error on appending value."
181181

182-
def extend(self, iter: Iterable[Any]) -> None:
182+
def extend(self, iterable: Iterable[Any]) -> None:
183183
"""
184-
Appends every value of iter to the end of the deque.
184+
Appends every value of iterable to the end of the deque.
185185
Time complexity: O(n)
186186
>>> our_deque_1 = Deque([1, 2, 3])
187187
>>> our_deque_1.extend([4, 5])
@@ -205,12 +205,12 @@ def extend(self, iter: Iterable[Any]) -> None:
205205
>>> list(our_deque_2) == list(deque_collections_2)
206206
True
207207
"""
208-
for val in iter:
208+
for val in iterable:
209209
self.append(val)
210210

211-
def extendleft(self, iter: Iterable[Any]) -> None:
211+
def extendleft(self, iterable: Iterable[Any]) -> None:
212212
"""
213-
Appends every value of iter to the beginning of the deque.
213+
Appends every value of iterable to the beginning of the deque.
214214
Time complexity: O(n)
215215
>>> our_deque_1 = Deque([1, 2, 3])
216216
>>> our_deque_1.extendleft([0, -1])
@@ -234,7 +234,7 @@ def extendleft(self, iter: Iterable[Any]) -> None:
234234
>>> list(our_deque_2) == list(deque_collections_2)
235235
True
236236
"""
237-
for val in iter:
237+
for val in iterable:
238238
self.appendleft(val)
239239

240240
def pop(self) -> Any:

0 commit comments

Comments
 (0)