Follow Flake8 pep3101 and remove modulo formatting (#7339)

* ci: Add ``flake8-pep3101`` plugin to ``pre-commit``

* refactor: Remove all modulo string formatting

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* refactor: Remove ``flake8-pep3101`` plugin from ``pre-commit``

* revert: Revert to modulo formatting

* refactor: Use f-string instead of `join`

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Caeden Perelli-Harris 2022-10-16 21:50:11 +01:00 committed by GitHub
parent 7f6e0b656f
commit f15cc2f01c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 15 additions and 19 deletions

View File

@ -41,22 +41,19 @@ def make_key_files(name: str, key_size: int) -> None:
if os.path.exists(f"{name}_pubkey.txt") or os.path.exists(f"{name}_privkey.txt"):
print("\nWARNING:")
print(
'"%s_pubkey.txt" or "%s_privkey.txt" already exists. \n'
f'"{name}_pubkey.txt" or "{name}_privkey.txt" already exists. \n'
"Use a different name or delete these files and re-run this program."
% (name, name)
)
sys.exit()
public_key, private_key = generate_key(key_size)
print(f"\nWriting public key to file {name}_pubkey.txt...")
with open(f"{name}_pubkey.txt", "w") as fo:
fo.write(
"%d,%d,%d,%d" % (public_key[0], public_key[1], public_key[2], public_key[3])
)
fo.write(f"{public_key[0]},{public_key[1]},{public_key[2]},{public_key[3]}")
print(f"Writing private key to file {name}_privkey.txt...")
with open(f"{name}_privkey.txt", "w") as fo:
fo.write("%d,%d" % (private_key[0], private_key[1]))
fo.write(f"{private_key[0]},{private_key[1]}")
def main() -> None:

View File

@ -37,9 +37,8 @@ def make_key_files(name: str, key_size: int) -> None:
if os.path.exists(f"{name}_pubkey.txt") or os.path.exists(f"{name}_privkey.txt"):
print("\nWARNING:")
print(
'"%s_pubkey.txt" or "%s_privkey.txt" already exists. \n'
f'"{name}_pubkey.txt" or "{name}_privkey.txt" already exists. \n'
"Use a different name or delete these files and re-run this program."
% (name, name)
)
sys.exit()

View File

@ -99,7 +99,7 @@ if __name__ == "__main__":
S2 = input("Enter the second string: ").strip()
print()
print("The minimum Edit Distance is: %d" % (solver.solve(S1, S2)))
print("The minimum Edit Distance is: %d" % (min_distance_bottom_up(S1, S2)))
print(f"The minimum Edit Distance is: {solver.solve(S1, S2)}")
print(f"The minimum Edit Distance is: {min_distance_bottom_up(S1, S2)}")
print()
print("*************** End of Testing Edit Distance DP Algorithm ***************")

View File

@ -172,7 +172,7 @@ if __name__ == "__main__":
" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm"
"nopqrstuvwxyz.,;!?+-*#@^'èéòà€ù=)(&%$£/\\"
)
generation, population, target = basic(target_str, genes_list)
print(
"\nGeneration: %s\nTotal Population: %s\nTarget: %s"
% basic(target_str, genes_list)
f"\nGeneration: {generation}\nTotal Population: {population}\nTarget: {target}"
)

View File

@ -63,7 +63,7 @@ class Graph:
for tail in self.adjacency:
for head in self.adjacency[tail]:
weight = self.adjacency[head][tail]
string += "%d -> %d == %d\n" % (head, tail, weight)
string += f"{head} -> {tail} == {weight}\n"
return string.rstrip("\n")
def get_edges(self):

View File

@ -82,7 +82,7 @@ def run_linear_regression(data_x, data_y):
for i in range(0, iterations):
theta = run_steep_gradient_descent(data_x, data_y, len_data, alpha, theta)
error = sum_of_square_error(data_x, data_y, len_data, theta)
print("At Iteration %d - Error is %.5f " % (i + 1, error))
print(f"At Iteration {i + 1} - Error is {error:.5f}")
return theta

View File

@ -31,14 +31,14 @@ class Matrix:
"""
# Prefix
s = "Matrix consist of %d rows and %d columns\n" % (self.row, self.column)
s = f"Matrix consist of {self.row} rows and {self.column} columns\n"
# Make string identifier
max_element_length = 0
for row_vector in self.array:
for obj in row_vector:
max_element_length = max(max_element_length, len(str(obj)))
string_format_identifier = "%%%ds" % (max_element_length,)
string_format_identifier = f"%{max_element_length}s"
# Make string and return
def single_line(row_vector: list[float]) -> str:
@ -252,7 +252,7 @@ if __name__ == "__main__":
v[0, 0], v[1, 0], v[2, 0] = 4, -2, 5
print(f"u is {u}")
print(f"v is {v}")
print("uv^T is %s" % (u * v.transpose()))
print(f"uv^T is {u * v.transpose()}")
# Sherman Morrison
print(f"(a + uv^T)^(-1) is {ainv.sherman_morrison(u, v)}")

View File

@ -117,7 +117,7 @@ class BPNN:
def summary(self):
for i, layer in enumerate(self.layers[:]):
print("------- layer %d -------" % i)
print(f"------- layer {i} -------")
print("weight.shape ", np.shape(layer.weight))
print("bias.shape ", np.shape(layer.bias))

View File

@ -219,7 +219,7 @@ class CNN:
mse = 10000
while rp < n_repeat and mse >= error_accuracy:
error_count = 0
print("-------------Learning Time %d--------------" % rp)
print(f"-------------Learning Time {rp}--------------")
for p in range(len(datas_train)):
# print('------------Learning Image: %d--------------'%p)
data_train = np.asmatrix(datas_train[p])