Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flake8 pluin flake8 bugbear to pre-commit #7132

Merged
merged 26 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6796e27
ci(pre-commit): Add ``flake8-builtins`` additional dependency to ``pr…
CaedenPH Oct 13, 2022
771e65b
refactor: Fix ``flake8-builtins`` (#7104)
CaedenPH Oct 13, 2022
4d8ac3e
fix(lru_cache): Fix naming conventions in docstrings (#7104)
CaedenPH Oct 13, 2022
c69b7d9
ci(pre-commit): Order additional dependencies alphabetically (#7104)
CaedenPH Oct 13, 2022
f13819e
fix(lfu_cache): Correct function name in docstring (#7104)
CaedenPH Oct 13, 2022
fa72f61
Update strings/snake_case_to_camel_pascal_case.py
CaedenPH Oct 13, 2022
1293059
Update data_structures/stacks/next_greater_element.py
CaedenPH Oct 13, 2022
a895249
Update digital_image_processing/index_calculation.py
CaedenPH Oct 13, 2022
eb5524b
Update graphs/prim.py
CaedenPH Oct 13, 2022
89a4005
Update hashes/djb2.py
CaedenPH Oct 13, 2022
f84bcd7
refactor: Rename `_builtin` to `builtin_` ( #7104)
CaedenPH Oct 13, 2022
c8d6d47
fix: Rename all instances (#7104)
CaedenPH Oct 13, 2022
244a3a3
refactor: Update variable names (#7104)
CaedenPH Oct 13, 2022
35787a1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 13, 2022
9874c44
ci: Create ``tox.ini`` and ignore ``A003`` (#7123)
CaedenPH Oct 13, 2022
fe0afdb
revert: Remove function name changes (#7104)
CaedenPH Oct 13, 2022
3d39ee9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 13, 2022
c46e021
Rename tox.ini to .flake8
dhruvmanila Oct 13, 2022
9f13912
Update data_structures/heap/heap.py
CaedenPH Oct 13, 2022
0d63a42
refactor: Rename `next_` to `next_item` (#7104)
CaedenPH Oct 13, 2022
2e2ce4e
Merge branch 'TheAlgorithms:master' into master
CaedenPH Oct 13, 2022
952d1a2
ci(pre-commit): Add `flake8` plugin `flake8-bugbear` (#7127)
CaedenPH Oct 13, 2022
214befd
refactor: Follow `flake8-bugbear` plugin (#7127)
CaedenPH Oct 13, 2022
0c48669
fix: Correct `knapsack` code (#7127)
CaedenPH Oct 13, 2022
19a1894
Merge branch 'TheAlgorithms:master' into flake8-bugbear
CaedenPH Oct 13, 2022
808ee5d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ repos:
- --ignore=E203,W503
- --max-complexity=25
- --max-line-length=88
additional_dependencies: [flake8-builtins, pep8-naming]
additional_dependencies:
- flake8-bugbear
- flake8-builtins
- pep8-naming

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.982
Expand Down
2 changes: 1 addition & 1 deletion arithmetic_analysis/jacobi_iteration_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def jacobi_iteration_method(
strictly_diagonally_dominant(table)

# Iterates the whole matrix for given number of times
for i in range(iterations):
for _ in range(iterations):
new_val = []
for row in range(rows):
temp = 0
Expand Down
2 changes: 1 addition & 1 deletion arithmetic_analysis/newton_forward_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def ucal(u: float, p: int) -> float:
def main() -> None:
n = int(input("enter the numbers of values: "))
y: list[list[float]] = []
for i in range(n):
for _ in range(n):
y.append([])
for i in range(n):
for j in range(n):
Expand Down
2 changes: 1 addition & 1 deletion arithmetic_analysis/secant_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def secant_method(lower_bound: float, upper_bound: float, repeats: int) -> float
"""
x0 = lower_bound
x1 = upper_bound
for i in range(0, repeats):
for _ in range(0, repeats):
x0, x1 = x1, x1 - (f(x1) * (x1 - x0)) / (f(x1) - f(x0))
return x1

Expand Down
23 changes: 16 additions & 7 deletions audio_filters/butterworth_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def make_lowpass(
frequency: int, samplerate: int, q_factor: float = 1 / sqrt(2)
frequency: int, samplerate: int, q_factor: float = 1 / sqrt(2) # noqa: B008
) -> IIRFilter:
"""
Creates a low-pass filter
Expand Down Expand Up @@ -39,7 +39,7 @@ def make_lowpass(


def make_highpass(
frequency: int, samplerate: int, q_factor: float = 1 / sqrt(2)
frequency: int, samplerate: int, q_factor: float = 1 / sqrt(2) # noqa: B008
) -> IIRFilter:
"""
Creates a high-pass filter
Expand Down Expand Up @@ -67,7 +67,7 @@ def make_highpass(


def make_bandpass(
frequency: int, samplerate: int, q_factor: float = 1 / sqrt(2)
frequency: int, samplerate: int, q_factor: float = 1 / sqrt(2) # noqa: B008
) -> IIRFilter:
"""
Creates a band-pass filter
Expand Down Expand Up @@ -96,7 +96,7 @@ def make_bandpass(


def make_allpass(
frequency: int, samplerate: int, q_factor: float = 1 / sqrt(2)
frequency: int, samplerate: int, q_factor: float = 1 / sqrt(2) # noqa: B008
) -> IIRFilter:
"""
Creates an all-pass filter
Expand All @@ -121,7 +121,10 @@ def make_allpass(


def make_peak(
frequency: int, samplerate: int, gain_db: float, q_factor: float = 1 / sqrt(2)
frequency: int,
samplerate: int,
gain_db: float,
q_factor: float = 1 / sqrt(2), # noqa: B008
) -> IIRFilter:
"""
Creates a peak filter
Expand Down Expand Up @@ -150,7 +153,10 @@ def make_peak(


def make_lowshelf(
frequency: int, samplerate: int, gain_db: float, q_factor: float = 1 / sqrt(2)
frequency: int,
samplerate: int,
gain_db: float,
q_factor: float = 1 / sqrt(2), # noqa: B008
) -> IIRFilter:
"""
Creates a low-shelf filter
Expand Down Expand Up @@ -184,7 +190,10 @@ def make_lowshelf(


def make_highshelf(
frequency: int, samplerate: int, gain_db: float, q_factor: float = 1 / sqrt(2)
frequency: int,
samplerate: int,
gain_db: float,
q_factor: float = 1 / sqrt(2), # noqa: B008
) -> IIRFilter:
"""
Creates a high-shelf filter
Expand Down
8 changes: 4 additions & 4 deletions backtracking/sum_of_subsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def create_state_space_tree(
if sum(path) == max_sum:
result.append(path)
return
for num_index in range(num_index, len(nums)):
for index in range(num_index, len(nums)):
create_state_space_tree(
nums,
max_sum,
num_index + 1,
path + [nums[num_index]],
index + 1,
path + [nums[index]],
result,
remaining_nums_sum - nums[num_index],
remaining_nums_sum - nums[index],
)


Expand Down
2 changes: 1 addition & 1 deletion boolean_algebra/quine_mc_cluskey.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def decimal_to_binary(no_of_variable: int, minterms: Sequence[float]) -> list[st
temp = []
for minterm in minterms:
string = ""
for i in range(no_of_variable):
for _ in range(no_of_variable):
string = str(minterm % 2) + string
minterm //= 2
temp.append(string)
Expand Down
2 changes: 1 addition & 1 deletion ciphers/mixed_keyword_cypher.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def mixed_keyword(key: str = "college", pt: str = "UNIVERSITY") -> str:
k = 0
for _ in range(r):
s = []
for j in range(len_temp):
for _ in range(len_temp):
s.append(temp[k])
if not (k < 25):
break
Expand Down
2 changes: 1 addition & 1 deletion ciphers/rabin_miller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def rabin_miller(num: int) -> bool:
s = s // 2
t += 1

for trials in range(5):
for _ in range(5):
a = random.randrange(2, num - 1)
v = pow(a, s, num)
if v != 1:
Expand Down
2 changes: 1 addition & 1 deletion compression/burrows_wheeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def reverse_bwt(bwt_string: str, idx_original_string: int) -> str:
)

ordered_rotations = [""] * len(bwt_string)
for x in range(len(bwt_string)):
for _ in range(len(bwt_string)):
for i in range(len(bwt_string)):
ordered_rotations[i] = bwt_string[i] + ordered_rotations[i]
ordered_rotations.sort()
Expand Down
8 changes: 4 additions & 4 deletions data_structures/binary_tree/binary_search_tree_recursive.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def test_put(self) -> None:
assert t.root.left.left.parent == t.root.left
assert t.root.left.left.label == 1

with self.assertRaises(Exception):
with self.assertRaises(Exception): # noqa: B017
t.put(1)

def test_search(self) -> None:
Expand All @@ -369,7 +369,7 @@ def test_search(self) -> None:
node = t.search(13)
assert node.label == 13

with self.assertRaises(Exception):
with self.assertRaises(Exception): # noqa: B017
t.search(2)

def test_remove(self) -> None:
Expand Down Expand Up @@ -515,7 +515,7 @@ def test_get_max_label(self) -> None:
assert t.get_max_label() == 14

t.empty()
with self.assertRaises(Exception):
with self.assertRaises(Exception): # noqa: B017
t.get_max_label()

def test_get_min_label(self) -> None:
Expand All @@ -524,7 +524,7 @@ def test_get_min_label(self) -> None:
assert t.get_min_label() == 1

t.empty()
with self.assertRaises(Exception):
with self.assertRaises(Exception): # noqa: B017
t.get_min_label()

def test_inorder_traversal(self) -> None:
Expand Down
8 changes: 4 additions & 4 deletions data_structures/linked_list/circular_linked_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,25 @@ def test_circular_linked_list() -> None:

try:
circular_linked_list.delete_front()
assert False # This should not happen
raise AssertionError() # This should not happen
except IndexError:
assert True # This should happen

try:
circular_linked_list.delete_tail()
assert False # This should not happen
raise AssertionError() # This should not happen
except IndexError:
assert True # This should happen

try:
circular_linked_list.delete_nth(-1)
assert False
raise AssertionError()
except IndexError:
assert True

try:
circular_linked_list.delete_nth(0)
assert False
raise AssertionError()
except IndexError:
assert True

Expand Down
8 changes: 4 additions & 4 deletions data_structures/linked_list/doubly_linked_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def insert_at_nth(self, index: int, data):
self.tail = new_node
else:
temp = self.head
for i in range(0, index):
for _ in range(0, index):
temp = temp.next
temp.previous.next = new_node
new_node.previous = temp.previous
Expand Down Expand Up @@ -145,7 +145,7 @@ def delete_at_nth(self, index: int):
self.tail.next = None
else:
temp = self.head
for i in range(0, index):
for _ in range(0, index):
temp = temp.next
delete_node = temp
temp.next.previous = temp.previous
Expand Down Expand Up @@ -194,13 +194,13 @@ def test_doubly_linked_list() -> None:

try:
linked_list.delete_head()
assert False # This should not happen.
raise AssertionError() # This should not happen.
except IndexError:
assert True # This should happen.

try:
linked_list.delete_tail()
assert False # This should not happen.
raise AssertionError() # This should not happen.
except IndexError:
assert True # This should happen.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def middle_element(self) -> int | None:

if __name__ == "__main__":
link = LinkedList()
for i in range(int(input().strip())):
for _ in range(int(input().strip())):
data = int(input().strip())
link.push(data)
print(link.middle_element())
6 changes: 3 additions & 3 deletions data_structures/linked_list/singly_linked_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __setitem__(self, index: int, data: Any) -> None:
if not 0 <= index < len(self):
raise ValueError("list index out of range.")
current = self.head
for i in range(index):
for _ in range(index):
current = current.next
current.data = data

Expand Down Expand Up @@ -352,13 +352,13 @@ def test_singly_linked_list() -> None:

try:
linked_list.delete_head()
assert False # This should not happen.
raise AssertionError() # This should not happen.
except IndexError:
assert True # This should happen.

try:
linked_list.delete_tail()
assert False # This should not happen.
raise AssertionError() # This should not happen.
except IndexError:
assert True # This should happen.

Expand Down
4 changes: 2 additions & 2 deletions data_structures/linked_list/skip_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def insert(self, key: KT, value: VT):

if level > self.level:
# After level increase we have to add additional nodes to head.
for i in range(self.level - 1, level):
for _ in range(self.level - 1, level):
update_vector.append(self.head)
self.level = level

Expand Down Expand Up @@ -407,7 +407,7 @@ def is_sorted(lst):


def pytests():
for i in range(100):
for _ in range(100):
# Repeat test 100 times due to the probabilistic nature of skip list
# random values == random bugs
test_insert()
Expand Down
2 changes: 1 addition & 1 deletion data_structures/queue/queue_on_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get(self):
number of times to rotate queue"""

def rotate(self, rotation):
for i in range(rotation):
for _ in range(rotation):
self.put(self.get())

"""Enqueues {@code item}
Expand Down
2 changes: 1 addition & 1 deletion data_structures/queue/queue_on_pseudo_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get(self) -> Any:
number of times to rotate queue"""

def rotate(self, rotation: int) -> None:
for i in range(rotation):
for _ in range(rotation):
temp = self.stack[0]
self.stack = self.stack[1:]
self.put(temp)
Expand Down
6 changes: 3 additions & 3 deletions data_structures/stacks/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ def test_stack() -> None:

try:
_ = stack.pop()
assert False # This should not happen
raise AssertionError() # This should not happen
except StackUnderflowError:
assert True # This should happen

try:
_ = stack.peek()
assert False # This should not happen
raise AssertionError() # This should not happen
except StackUnderflowError:
assert True # This should happen

Expand All @@ -118,7 +118,7 @@ def test_stack() -> None:

try:
stack.push(200)
assert False # This should not happen
raise AssertionError() # This should not happen
except StackOverflowError:
assert True # This should happen

Expand Down
8 changes: 4 additions & 4 deletions divide_and_conquer/convex_hull.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,16 +458,16 @@ def convex_hull_melkman(points: list[Point]) -> list[Point]:
convex_hull[1] = points[i]
i += 1

for i in range(i, n):
for j in range(i, n):
if (
_det(convex_hull[0], convex_hull[-1], points[i]) > 0
_det(convex_hull[0], convex_hull[-1], points[j]) > 0
and _det(convex_hull[-1], convex_hull[0], points[1]) < 0
):
# The point lies within the convex hull
continue

convex_hull.insert(0, points[i])
convex_hull.append(points[i])
convex_hull.insert(0, points[j])
convex_hull.append(points[j])
while _det(convex_hull[0], convex_hull[1], convex_hull[2]) >= 0:
del convex_hull[1]
while _det(convex_hull[-1], convex_hull[-2], convex_hull[-3]) <= 0:
Expand Down
Loading