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

FIx pre-commit failing - Add B023 to .flake8 ignores #7941

Closed
wants to merge 12 commits into from
5 changes: 3 additions & 2 deletions .flake8
@@ -1,8 +1,9 @@
[flake8]
max-line-length = 88
max-complexity = 25

# Should be 10
max-complexity = 23
extend-ignore =
A003 # Class attribute is shadowing a python builtin
# Formatting style for `black`
E203 # Whitespace before ':'
W503 # Line break occurred before a binary operator
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Expand Up @@ -33,21 +33,21 @@ repos:
args:
- --py310-plus

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
- repo: https://github.com/asottile/yesqa
rev: v1.4.0
hooks:
- id: flake8 # See .flake8 for args
- id: yesqa
additional_dependencies: &flake8-plugins
- flake8-bugbear
- flake8-builtins
- flake8-broken-line
- flake8-comprehensions
- pep8-naming

- repo: https://github.com/asottile/yesqa
rev: v1.4.0
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: yesqa
- id: flake8 # See .flake8 for args
additional_dependencies:
*flake8-plugins

Expand Down
2 changes: 1 addition & 1 deletion arithmetic_analysis/newton_raphson.py
Expand Up @@ -5,7 +5,7 @@
from __future__ import annotations

from decimal import Decimal
from math import * # noqa: F401, F403
from math import *

from sympy import diff

Expand Down
2 changes: 1 addition & 1 deletion arithmetic_analysis/newton_raphson_new.py
Expand Up @@ -8,7 +8,7 @@
# Newton's Method - https://en.wikipedia.org/wiki/Newton's_method

from sympy import diff, lambdify, symbols
from sympy.functions import * # noqa: F401, F403
from sympy.functions import *


def newton_raphson(
Expand Down
14 changes: 7 additions & 7 deletions audio_filters/butterworth_filter.py
Expand Up @@ -11,7 +11,7 @@


def make_lowpass(
frequency: int, samplerate: int, q_factor: float = 1 / sqrt(2) # noqa: B008
frequency: int, samplerate: int, q_factor: float = 1 / sqrt(2)
) -> 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) # noqa: B008
frequency: int, samplerate: int, q_factor: float = 1 / sqrt(2)
) -> 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) # noqa: B008
frequency: int, samplerate: int, q_factor: float = 1 / sqrt(2)
) -> 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) # noqa: B008
frequency: int, samplerate: int, q_factor: float = 1 / sqrt(2)
) -> IIRFilter:
"""
Creates an all-pass filter
Expand Down Expand Up @@ -124,7 +124,7 @@ def make_peak(
frequency: int,
samplerate: int,
gain_db: float,
q_factor: float = 1 / sqrt(2), # noqa: B008
q_factor: float = 1 / sqrt(2),
) -> IIRFilter:
"""
Creates a peak filter
Expand Down Expand Up @@ -156,7 +156,7 @@ def make_lowshelf(
frequency: int,
samplerate: int,
gain_db: float,
q_factor: float = 1 / sqrt(2), # noqa: B008
q_factor: float = 1 / sqrt(2),
) -> IIRFilter:
"""
Creates a low-shelf filter
Expand Down Expand Up @@ -193,7 +193,7 @@ def make_highshelf(
frequency: int,
samplerate: int,
gain_db: float,
q_factor: float = 1 / sqrt(2), # noqa: B008
q_factor: float = 1 / sqrt(2),
) -> IIRFilter:
"""
Creates a high-shelf filter
Expand Down
4 changes: 2 additions & 2 deletions ciphers/rsa_key_generator.py
Expand Up @@ -2,8 +2,8 @@
import random
import sys

from . import cryptomath_module as cryptoMath # noqa: N812
from . import rabin_miller as rabinMiller # noqa: N812
from . import cryptomath_module as cryptoMath
from . import rabin_miller as rabinMiller


def main() -> None:
Expand Down
8 changes: 4 additions & 4 deletions data_structures/binary_tree/binary_search_tree_recursive.py
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): # noqa: B017
with self.assertRaises(Exception):
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): # noqa: B017
with self.assertRaises(Exception):
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): # noqa: B017
with self.assertRaises(Exception):
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): # noqa: B017
with self.assertRaises(Exception):
t.get_min_label()

def test_inorder_traversal(self) -> None:
Expand Down
8 changes: 4 additions & 4 deletions data_structures/binary_tree/fenwick_tree.py
Expand Up @@ -46,7 +46,7 @@ def init(self, arr: list[int]) -> None:
self.size = len(arr)
self.tree = deepcopy(arr)
for i in range(1, self.size):
j = self.next(i)
j = self.next_(i)
if j < self.size:
self.tree[j] += self.tree[i]

Expand All @@ -64,13 +64,13 @@ def get_array(self) -> list[int]:
"""
arr = self.tree[:]
for i in range(self.size - 1, 0, -1):
j = self.next(i)
j = self.next_(i)
if j < self.size:
arr[j] -= arr[i]
return arr

@staticmethod
def next(index: int) -> int:
def next_(index: int) -> int:
return index + (index & (-index))

@staticmethod
Expand Down Expand Up @@ -102,7 +102,7 @@ def add(self, index: int, value: int) -> None:
return
while index < self.size:
self.tree[index] += value
index = self.next(index)
index = self.next_(index)

def update(self, index: int, value: int) -> None:
"""
Expand Down
4 changes: 2 additions & 2 deletions data_structures/binary_tree/non_recursive_segment_tree.py
Expand Up @@ -86,7 +86,7 @@ def update(self, p: int, v: T) -> None:
p = p // 2
self.st[p] = self.fn(self.st[p * 2], self.st[p * 2 + 1])

def query(self, l: int, r: int) -> T | None: # noqa: E741
def query(self, l: int, r: int) -> T | None:
"""
Get range query value in log(N) time
:param l: left element index
Expand All @@ -106,7 +106,7 @@ def query(self, l: int, r: int) -> T | None: # noqa: E741
l, r = l + self.N, r + self.N

res: T | None = None
while l <= r: # noqa: E741
while l <= r:
if l % 2 == 1:
res = self.st[l] if res is None else self.fn(res, self.st[l])
if r % 2 == 0:
Expand Down
12 changes: 6 additions & 6 deletions data_structures/binary_tree/segment_tree.py
Expand Up @@ -15,8 +15,8 @@ def left(self, idx):
def right(self, idx):
return idx * 2 + 1

def build(self, idx, l, r): # noqa: E741
if l == r: # noqa: E741
def build(self, idx, l, r):
if l == r:
self.st[idx] = A[l]
else:
mid = (l + r) // 2
Expand All @@ -27,13 +27,13 @@ def build(self, idx, l, r): # noqa: E741
def update(self, a, b, val):
return self.update_recursive(1, 0, self.N - 1, a - 1, b - 1, val)

def update_recursive(self, idx, l, r, a, b, val): # noqa: E741
def update_recursive(self, idx, l, r, a, b, val):
"""
update(1, 1, N, a, b, v) for update val v to [a,b]
"""
if r < a or l > b:
return True
if l == r: # noqa: E741
if l == r:
self.st[idx] = val
return True
mid = (l + r) // 2
Expand All @@ -45,13 +45,13 @@ def update_recursive(self, idx, l, r, a, b, val): # noqa: E741
def query(self, a, b):
return self.query_recursive(1, 0, self.N - 1, a - 1, b - 1)

def query_recursive(self, idx, l, r, a, b): # noqa: E741
def query_recursive(self, idx, l, r, a, b):
"""
query(1, 1, N, a, b) for query max of [a,b]
"""
if r < a or l > b:
return -math.inf
if l >= a and r <= b: # noqa: E741
if l >= a and r <= b:
return self.st[idx]
mid = (l + r) // 2
q1 = self.query_recursive(self.left(idx), l, mid, a, b)
Expand Down
12 changes: 6 additions & 6 deletions data_structures/heap/heap.py
Expand Up @@ -88,12 +88,12 @@ def build_max_heap(self, collection: Iterable[float]) -> None:
for i in range(self.heap_size // 2 - 1, -1, -1):
self.max_heapify(i)

def max(self) -> float:
"""return the max in the heap"""
if self.heap_size >= 1:
return self.h[0]
else:
raise Exception("Empty heap")
# def max(self) -> float:
# """return the max in the heap"""
# if self.heap_size >= 1:
# return self.h[0]
# else:
# raise Exception("Empty heap")

def extract_max(self) -> float:
"""get and remove max from heap"""
Expand Down
2 changes: 1 addition & 1 deletion data_structures/heap/min_heap.py
Expand Up @@ -66,7 +66,7 @@ def build_heap(self, array):
# this is min-heapify method
def sift_down(self, idx, array):
while True:
l = self.get_left_child_idx(idx) # noqa: E741
l = self.get_left_child_idx(idx)
r = self.get_right_child_idx(idx)

smallest = idx
Expand Down
2 changes: 1 addition & 1 deletion data_structures/linked_list/__init__.py
Expand Up @@ -11,7 +11,7 @@


class Node:
def __init__(self, item: Any, next: Any) -> None: # noqa: A002
def __init__(self, item: Any, next: Any) -> None:
self.item = item
self.next = next

Expand Down
4 changes: 2 additions & 2 deletions data_structures/linked_list/merge_two_lists.py
Expand Up @@ -13,7 +13,7 @@
@dataclass
class Node:
data: int
next: Node | None
next_node: Node | None


class SortedLinkedList:
Expand All @@ -32,7 +32,7 @@ def __iter__(self) -> Iterator[int]:
node = self.head
while node:
yield node.data
node = node.next
node = node.next_node

def __len__(self) -> int:
"""
Expand Down