Skip to content

The black formatter is no longer beta #5960

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

Merged
merged 5 commits into from
Jan 30, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.1.0
hooks:
- id: check-executables-have-shebangs
- id: check-yaml
Expand All @@ -14,26 +14,26 @@ repos:
- id: requirements-txt-fixer

- repo: https://github.com/psf/black
rev: 21.4b0
rev: 22.1.0
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.8.0
rev: 5.10.1
hooks:
- id: isort
args:
- --profile=black

- repo: https://github.com/asottile/pyupgrade
rev: v2.29.0
rev: v2.31.0
hooks:
- id: pyupgrade
args:
- --py39-plus

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.1
rev: 3.9.2
hooks:
- id: flake8
args:
Expand All @@ -42,7 +42,7 @@ repos:
- --max-line-length=88

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910
rev: v0.931
hooks:
- id: mypy
args:
Expand All @@ -51,11 +51,11 @@ repos:
- --non-interactive

- repo: https://github.com/codespell-project/codespell
rev: v2.0.0
rev: v2.1.0
hooks:
- id: codespell
args:
- --ignore-words-list=ans,crate,fo,followings,hist,iff,mater,secant,som,tim
- --ignore-words-list=ans,crate,fo,followings,hist,iff,mater,secant,som,sur,tim
- --skip="./.*,./strings/dictionary.txt,./strings/words.txt,./project_euler/problem_022/p022_names.txt"
exclude: |
(?x)^(
Expand Down
4 changes: 2 additions & 2 deletions arithmetic_analysis/bisection.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def bisection(function: Callable[[float], float], a: float, b: float) -> float:
raise ValueError("could not find root in given interval.")
else:
mid: float = start + (end - start) / 2.0
while abs(start - mid) > 10 ** -7: # until precisely equals to 10^-7
while abs(start - mid) > 10**-7: # until precisely equals to 10^-7
if function(mid) == 0:
return mid
elif function(mid) * function(start) < 0:
Expand All @@ -44,7 +44,7 @@ def bisection(function: Callable[[float], float], a: float, b: float) -> float:


def f(x: float) -> float:
return x ** 3 - 2 * x - 5
return x**3 - 2 * x - 5


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion arithmetic_analysis/in_static_equilibrium.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def polar_force(


def in_static_equilibrium(
forces: ndarray, location: ndarray, eps: float = 10 ** -1
forces: ndarray, location: ndarray, eps: float = 10**-1
) -> bool:
"""
Check if a system is in equilibrium.
Expand Down
2 changes: 1 addition & 1 deletion arithmetic_analysis/intersection.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def intersection(function: Callable[[float], float], x0: float, x1: float) -> fl
x_n2: float = x_n1 - (
function(x_n1) / ((function(x_n1) - function(x_n)) / (x_n1 - x_n))
)
if abs(x_n2 - x_n1) < 10 ** -5:
if abs(x_n2 - x_n1) < 10**-5:
return x_n2
x_n = x_n1
x_n1 = x_n2
Expand Down
6 changes: 3 additions & 3 deletions arithmetic_analysis/newton_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ def newton(
next_guess = prev_guess - function(prev_guess) / derivative(prev_guess)
except ZeroDivisionError:
raise ZeroDivisionError("Could not find root") from None
if abs(prev_guess - next_guess) < 10 ** -5:
if abs(prev_guess - next_guess) < 10**-5:
return next_guess
prev_guess = next_guess


def f(x: float) -> float:
return (x ** 3) - (2 * x) - 5
return (x**3) - (2 * x) - 5


def f1(x: float) -> float:
return 3 * (x ** 2) - 2
return 3 * (x**2) - 2


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion arithmetic_analysis/newton_raphson.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def newton_raphson(
func: str, a: float | Decimal, precision: float = 10 ** -10
func: str, a: float | Decimal, precision: float = 10**-10
) -> float:
"""Finds root from the point 'a' onwards by Newton-Raphson method
>>> newton_raphson("sin(x)", 2)
Expand Down
2 changes: 1 addition & 1 deletion ciphers/deterministic_miller_rabin.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def miller_rabin(n: int, allow_probable: bool = False) -> bool:
for prime in plist:
pr = False
for r in range(s):
m = pow(prime, d * 2 ** r, n)
m = pow(prime, d * 2**r, n)
# see article for analysis explanation for m
if (r == 0 and m == 1) or ((m + 1) % n == 0):
pr = True
Expand Down
2 changes: 1 addition & 1 deletion ciphers/rabin_miller.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def rabinMiller(num: int) -> bool:
return False
else:
i = i + 1
v = (v ** 2) % num
v = (v**2) % num
return True


Expand Down
4 changes: 2 additions & 2 deletions ciphers/rsa_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def get_text_from_blocks(
block_message: list[str] = []
for i in range(block_size - 1, -1, -1):
if len(message) + i < message_length:
ascii_number = block_int // (BYTE_SIZE ** i)
block_int = block_int % (BYTE_SIZE ** i)
ascii_number = block_int // (BYTE_SIZE**i)
block_int = block_int % (BYTE_SIZE**i)
block_message.insert(0, chr(ascii_number))
message.extend(block_message)
return "".join(message)
Expand Down
2 changes: 1 addition & 1 deletion ciphers/rsa_factorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def rsafactor(d: int, e: int, N: int) -> list[int]:
while True:
if t % 2 == 0:
t = t // 2
x = (g ** t) % N
x = (g**t) % N
y = math.gcd(x - 1, N)
if x > 1 and y > 1:
p = y
Expand Down
8 changes: 4 additions & 4 deletions computer_vision/harris_corner.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def detect(self, img_path: str) -> tuple[cv2.Mat, list[list[int]]]:
color_img = img.copy()
color_img = cv2.cvtColor(color_img, cv2.COLOR_GRAY2RGB)
dy, dx = np.gradient(img)
ixx = dx ** 2
iyy = dy ** 2
ixx = dx**2
iyy = dy**2
ixy = dx * dy
k = 0.04
offset = self.window_size // 2
Expand All @@ -56,9 +56,9 @@ def detect(self, img_path: str) -> tuple[cv2.Mat, list[list[int]]]:
y - offset : y + offset + 1, x - offset : x + offset + 1
].sum()

det = (wxx * wyy) - (wxy ** 2)
det = (wxx * wyy) - (wxy**2)
trace = wxx + wyy
r = det - k * (trace ** 2)
r = det - k * (trace**2)
# Can change the value
if r > 0.5:
corner_list.append([x, y, r])
Expand Down
2 changes: 1 addition & 1 deletion digital_image_processing/filters/gabor_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def gabor_filter_kernel(

# fill kernel
gabor[y, x] = np.exp(
-(_x ** 2 + gamma ** 2 * _y ** 2) / (2 * sigma ** 2)
-(_x**2 + gamma**2 * _y**2) / (2 * sigma**2)
) * np.cos(2 * np.pi * _x / lambd + psi)

return gabor
Expand Down
6 changes: 3 additions & 3 deletions digital_image_processing/index_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def CVI(self):
https://www.indexdatabase.de/db/i-single.php?id=391
:return: index
"""
return self.nir * (self.red / (self.green ** 2))
return self.nir * (self.red / (self.green**2))

def GLI(self):
"""
Expand Down Expand Up @@ -295,7 +295,7 @@ def ATSAVI(self, X=0.08, a=1.22, b=0.03):
"""
return a * (
(self.nir - a * self.red - b)
/ (a * self.nir + self.red - a * b + X * (1 + a ** 2))
/ (a * self.nir + self.red - a * b + X * (1 + a**2))
)

def BWDRVI(self):
Expand Down Expand Up @@ -363,7 +363,7 @@ def GEMI(self):
https://www.indexdatabase.de/db/i-single.php?id=25
:return: index
"""
n = (2 * (self.nir ** 2 - self.red ** 2) + 1.5 * self.nir + 0.5 * self.red) / (
n = (2 * (self.nir**2 - self.red**2) + 1.5 * self.nir + 0.5 * self.red) / (
self.nir + self.red + 0.5
)
return n * (1 - 0.25 * n) - (self.red - 0.125) / (1 - self.red)
Expand Down
4 changes: 2 additions & 2 deletions electronics/carrier_concentration.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ def carrier_concentration(
elif electron_conc == 0:
return (
"electron_conc",
intrinsic_conc ** 2 / hole_conc,
intrinsic_conc**2 / hole_conc,
)
elif hole_conc == 0:
return (
"hole_conc",
intrinsic_conc ** 2 / electron_conc,
intrinsic_conc**2 / electron_conc,
)
elif intrinsic_conc == 0:
return (
Expand Down
6 changes: 3 additions & 3 deletions electronics/coulombs_law.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ def couloumbs_law(
if distance < 0:
raise ValueError("Distance cannot be negative")
if force == 0:
force = COULOMBS_CONSTANT * charge_product / (distance ** 2)
force = COULOMBS_CONSTANT * charge_product / (distance**2)
return {"force": force}
elif charge1 == 0:
charge1 = abs(force) * (distance ** 2) / (COULOMBS_CONSTANT * charge2)
charge1 = abs(force) * (distance**2) / (COULOMBS_CONSTANT * charge2)
return {"charge1": charge1}
elif charge2 == 0:
charge2 = abs(force) * (distance ** 2) / (COULOMBS_CONSTANT * charge1)
charge2 = abs(force) * (distance**2) / (COULOMBS_CONSTANT * charge1)
return {"charge2": charge2}
elif distance == 0:
distance = (COULOMBS_CONSTANT * charge_product / abs(force)) ** 0.5
Expand Down
2 changes: 1 addition & 1 deletion graphics/bezier_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def basis_function(self, t: float) -> list[float]:
for i in range(len(self.list_of_points)):
# basis function for each i
output_values.append(
comb(self.degree, i) * ((1 - t) ** (self.degree - i)) * (t ** i)
comb(self.degree, i) * ((1 - t) ** (self.degree - i)) * (t**i)
)
# the basis must sum up to 1 for it to produce a valid Bezier curve.
assert round(sum(output_values), 5) == 1
Expand Down
2 changes: 1 addition & 1 deletion graphs/bidirectional_a_star.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def calculate_heuristic(self) -> float:
if HEURISTIC == 1:
return abs(dx) + abs(dy)
else:
return sqrt(dy ** 2 + dx ** 2)
return sqrt(dy**2 + dx**2)

def __lt__(self, other: Node) -> bool:
return self.f_cost < other.f_cost
Expand Down
4 changes: 2 additions & 2 deletions hashes/chaos_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def xorshift(X, Y):
params_space[key] = (machine_time * 0.01 + r * 1.01) % 1 + 3

# Choosing Chaotic Data
X = int(buffer_space[(key + 2) % m] * (10 ** 10))
Y = int(buffer_space[(key - 2) % m] * (10 ** 10))
X = int(buffer_space[(key + 2) % m] * (10**10))
Y = int(buffer_space[(key - 2) % m] * (10**10))

# Machine Time
machine_time += 1
Expand Down
2 changes: 1 addition & 1 deletion hashes/hamming_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def emitterConverter(sizePar, data):
>>> emitterConverter(4, "101010111111")
['1', '1', '1', '1', '0', '1', '0', '0', '1', '0', '1', '1', '1', '1', '1', '1']
"""
if sizePar + len(data) <= 2 ** sizePar - (len(data) - 1):
if sizePar + len(data) <= 2**sizePar - (len(data) - 1):
print("ERROR - size of parity don't match with size of data")
exit(0)

Expand Down
6 changes: 3 additions & 3 deletions hashes/md5.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def not32(i):


def sum32(a, b):
return (a + b) % 2 ** 32
return (a + b) % 2**32


def leftrot32(i, s):
Expand All @@ -114,7 +114,7 @@ def md5me(testString):
bs += format(ord(i), "08b")
bs = pad(bs)

tvals = [int(2 ** 32 * abs(math.sin(i + 1))) for i in range(64)]
tvals = [int(2**32 * abs(math.sin(i + 1))) for i in range(64)]

a0 = 0x67452301
b0 = 0xEFCDAB89
Expand Down Expand Up @@ -211,7 +211,7 @@ def md5me(testString):
dtemp = D
D = C
C = B
B = sum32(B, leftrot32((A + f + tvals[i] + m[g]) % 2 ** 32, s[i]))
B = sum32(B, leftrot32((A + f + tvals[i] + m[g]) % 2**32, s[i]))
A = dtemp
a0 = sum32(a0, A)
b0 = sum32(b0, B)
Expand Down
2 changes: 1 addition & 1 deletion linear_algebra/src/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def euclidean_length(self) -> float:
"""
if len(self.__components) == 0:
raise Exception("Vector is empty")
squares = [c ** 2 for c in self.__components]
squares = [c**2 for c in self.__components]
return math.sqrt(sum(squares))

def angle(self, other: Vector, deg: bool = False) -> float:
Expand Down
2 changes: 1 addition & 1 deletion machine_learning/k_means_clust.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def compute_heterogeneity(data, k, centroids, cluster_assignment):
distances = pairwise_distances(
member_data_points, [centroids[i]], metric="euclidean"
)
squared_distances = distances ** 2
squared_distances = distances**2
heterogeneity += np.sum(squared_distances)

return heterogeneity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def weighted_matrix(point: np.mat, training_data_x: np.mat, bandwidth: float) ->
# calculating weights for all training examples [x(i)'s]
for j in range(m):
diff = point - training_data_x[j]
weights[j, j] = np.exp(diff * diff.T / (-2.0 * bandwidth ** 2))
weights[j, j] = np.exp(diff * diff.T / (-2.0 * bandwidth**2))
return weights


Expand Down
8 changes: 4 additions & 4 deletions machine_learning/sequential_minimum_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,15 @@ def _get_new_alpha(self, i1, i2, a1, a2, e1, e2, y1, y2):
ol = (
l1 * f1
+ L * f2
+ 1 / 2 * l1 ** 2 * K(i1, i1)
+ 1 / 2 * L ** 2 * K(i2, i2)
+ 1 / 2 * l1**2 * K(i1, i1)
+ 1 / 2 * L**2 * K(i2, i2)
+ s * L * l1 * K(i1, i2)
)
oh = (
h1 * f1
+ H * f2
+ 1 / 2 * h1 ** 2 * K(i1, i1)
+ 1 / 2 * H ** 2 * K(i2, i2)
+ 1 / 2 * h1**2 * K(i1, i1)
+ 1 / 2 * H**2 * K(i2, i2)
+ s * H * h1 * K(i1, i2)
)
"""
Expand Down
Loading