Skip to content

Commit ed8d920

Browse files
[pre-commit.ci] pre-commit autoupdate (TheAlgorithms#11275)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/astral-sh/ruff-pre-commit: v0.1.14 → v0.2.0](astral-sh/ruff-pre-commit@v0.1.14...v0.2.0) * Upgrade pyproject.toml * Revert sudoku_solver.py RUF017 Avoid quadratic list summation --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <[email protected]>
1 parent 4128f19 commit ed8d920

File tree

11 files changed

+25
-39
lines changed

11 files changed

+25
-39
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repos:
1616
- id: auto-walrus
1717

1818
- repo: https://github.com/astral-sh/ruff-pre-commit
19-
rev: v0.1.14
19+
rev: v0.2.0
2020
hooks:
2121
- id: ruff
2222
- id: ruff-format

ciphers/mixed_keyword_cypher.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def mixed_keyword(
6767
if verbose:
6868
print(mapping)
6969
# create the encrypted text by mapping the plaintext to the modified alphabet
70-
return "".join(mapping[char] if char in mapping else char for char in plaintext)
70+
return "".join(mapping.get(char, char) for char in plaintext)
7171

7272

7373
if __name__ == "__main__":

data_structures/arrays/sudoku_solver.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def cross(items_a, items_b):
2222
+ [cross(rs, cs) for rs in ("ABC", "DEF", "GHI") for cs in ("123", "456", "789")]
2323
)
2424
units = {s: [u for u in unitlist if s in u] for s in squares}
25-
peers = {s: set(sum(units[s], [])) - {s} for s in squares}
25+
peers = {s: set(sum(units[s], [])) - {s} for s in squares} # noqa: RUF017
2626

2727

2828
def test():

data_structures/linked_list/is_palindrome.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,9 @@ def is_palindrome_dict(head: ListNode | None) -> bool:
171171
if len(v) % 2 != 0:
172172
middle += 1
173173
else:
174-
step = 0
175-
for i in range(len(v)):
174+
for step, i in enumerate(range(len(v))):
176175
if v[i] + v[len(v) - 1 - step] != checksum:
177176
return False
178-
step += 1
179177
if middle > 1:
180178
return False
181179
return True

digital_image_processing/filters/gaussian_filter.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ def gaussian_filter(image, k_size, sigma):
2222

2323
# im2col, turn the k_size*k_size pixels into a row and np.vstack all rows
2424
image_array = zeros((dst_height * dst_width, k_size * k_size))
25-
row = 0
26-
for i, j in product(range(dst_height), range(dst_width)):
25+
for row, (i, j) in enumerate(product(range(dst_height), range(dst_width))):
2726
window = ravel(image[i : i + k_size, j : j + k_size])
2827
image_array[row, :] = window
29-
row += 1
3028

3129
# turn the kernel into shape(k*k, 1)
3230
gaussian_kernel = gen_gaussian_kernel(k_size, sigma)

electronics/resistor_equivalence.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ def resistor_parallel(resistors: list[float]) -> float:
2020
"""
2121

2222
first_sum = 0.00
23-
index = 0
24-
for resistor in resistors:
23+
for index, resistor in enumerate(resistors):
2524
if resistor <= 0:
2625
msg = f"Resistor at index {index} has a negative or zero value!"
2726
raise ValueError(msg)
2827
first_sum += 1 / float(resistor)
29-
index += 1
3028
return 1 / first_sum
3129

3230

@@ -44,13 +42,11 @@ def resistor_series(resistors: list[float]) -> float:
4442
ValueError: Resistor at index 2 has a negative value!
4543
"""
4644
sum_r = 0.00
47-
index = 0
48-
for resistor in resistors:
45+
for index, resistor in enumerate(resistors):
4946
sum_r += resistor
5047
if resistor < 0:
5148
msg = f"Resistor at index {index} has a negative value!"
5249
raise ValueError(msg)
53-
index += 1
5450
return sum_r
5551

5652

hashes/hamming_code.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,14 @@ def emitter_converter(size_par, data):
123123
# Bit counter one for a given parity
124124
cont_bo = 0
125125
# counter to control the loop reading
126-
cont_loop = 0
127-
for x in data_ord:
126+
for cont_loop, x in enumerate(data_ord):
128127
if x is not None:
129128
try:
130129
aux = (bin_pos[cont_loop])[-1 * (bp)]
131130
except IndexError:
132131
aux = "0"
133132
if aux == "1" and x == "1":
134133
cont_bo += 1
135-
cont_loop += 1
136134
parity.append(cont_bo % 2)
137135

138136
qtd_bp += 1
@@ -164,21 +162,20 @@ def receptor_converter(size_par, data):
164162
parity_received = []
165163
data_output = []
166164

167-
for x in range(1, len(data) + 1):
165+
for i, item in enumerate(data, 1):
168166
# Performs a template of bit positions - who should be given,
169167
# and who should be parity
170-
if qtd_bp < size_par and (np.log(x) / np.log(2)).is_integer():
168+
if qtd_bp < size_par and (np.log(i) / np.log(2)).is_integer():
171169
data_out_gab.append("P")
172170
qtd_bp = qtd_bp + 1
173171
else:
174172
data_out_gab.append("D")
175173

176174
# Sorts the data to the new output size
177175
if data_out_gab[-1] == "D":
178-
data_output.append(data[cont_data])
176+
data_output.append(item)
179177
else:
180-
parity_received.append(data[cont_data])
181-
cont_data += 1
178+
parity_received.append(item)
182179

183180
# -----------calculates the parity with the data
184181
data_out = []
@@ -215,17 +212,14 @@ def receptor_converter(size_par, data):
215212
for bp in range(1, size_par + 1):
216213
# Bit counter one for a certain parity
217214
cont_bo = 0
218-
# Counter to control loop reading
219-
cont_loop = 0
220-
for x in data_ord:
215+
for cont_loop, x in enumerate(data_ord):
221216
if x is not None:
222217
try:
223218
aux = (bin_pos[cont_loop])[-1 * (bp)]
224219
except IndexError:
225220
aux = "0"
226221
if aux == "1" and x == "1":
227222
cont_bo += 1
228-
cont_loop += 1
229223
parity.append(str(cont_bo % 2))
230224

231225
qtd_bp += 1

machine_learning/k_means_clust.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def report_generator(
237237
[
238238
("sum", "sum"),
239239
("mean_with_zeros", lambda x: np.mean(np.nan_to_num(x))),
240-
("mean_without_zeros", lambda x: x.replace(0, np.NaN).mean()),
240+
("mean_without_zeros", lambda x: x.replace(0, np.nan).mean()),
241241
(
242242
"mean_25-75",
243243
lambda x: np.mean(

machine_learning/sequential_minimum_optimization.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ def plot_partition_boundary(
589589
ax.contour(
590590
xrange,
591591
yrange,
592-
np.mat(grid).T,
592+
np.asmatrix(grid).T,
593593
levels=(-1, 0, 1),
594594
linestyles=("--", "-", "--"),
595595
linewidths=(1, 1, 1),

neural_network/convolution_neural_network.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ def __init__(
4141
self.rate_weight = rate_w
4242
self.rate_thre = rate_t
4343
self.w_conv1 = [
44-
np.mat(-1 * np.random.rand(self.conv1[0], self.conv1[0]) + 0.5)
44+
np.asmatrix(-1 * np.random.rand(self.conv1[0], self.conv1[0]) + 0.5)
4545
for i in range(self.conv1[1])
4646
]
47-
self.wkj = np.mat(-1 * np.random.rand(self.num_bp3, self.num_bp2) + 0.5)
48-
self.vji = np.mat(-1 * np.random.rand(self.num_bp2, self.num_bp1) + 0.5)
47+
self.wkj = np.asmatrix(-1 * np.random.rand(self.num_bp3, self.num_bp2) + 0.5)
48+
self.vji = np.asmatrix(-1 * np.random.rand(self.num_bp2, self.num_bp1) + 0.5)
4949
self.thre_conv1 = -2 * np.random.rand(self.conv1[1]) + 1
5050
self.thre_bp2 = -2 * np.random.rand(self.num_bp2) + 1
5151
self.thre_bp3 = -2 * np.random.rand(self.num_bp3) + 1

pyproject.toml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.ruff]
2-
ignore = [ # `ruff rule S101` for a description of that rule
2+
lint.ignore = [ # `ruff rule S101` for a description of that rule
33
"ARG001", # Unused function argument `amount` -- FIX ME?
44
"B904", # Within an `except` clause, raise exceptions with `raise ... from err` -- FIX ME
55
"B905", # `zip()` without an explicit `strict=` parameter -- FIX ME
@@ -31,7 +31,7 @@ ignore = [ # `ruff rule S101` for a description of that rule
3131
"SLF001", # Private member accessed: `_Iterator` -- FIX ME
3232
"UP038", # Use `X | Y` in `{}` call instead of `(X, Y)` -- DO NOT FIX
3333
]
34-
select = [ # https://beta.ruff.rs/docs/rules
34+
lint.select = [ # https://beta.ruff.rs/docs/rules
3535
"A", # flake8-builtins
3636
"ARG", # flake8-unused-arguments
3737
"ASYNC", # flake8-async
@@ -84,13 +84,13 @@ select = [ # https://beta.ruff.rs/docs/rules
8484
# "TCH", # flake8-type-checking
8585
# "TRY", # tryceratops
8686
]
87-
show-source = true
88-
target-version = "py311"
87+
output-format = "full"
88+
target-version = "py312"
8989

90-
[tool.ruff.mccabe] # DO NOT INCREASE THIS VALUE
90+
[tool.ruff.lint.mccabe] # DO NOT INCREASE THIS VALUE
9191
max-complexity = 17 # default: 10
9292

93-
[tool.ruff.per-file-ignores]
93+
[tool.ruff.lint.per-file-ignores]
9494
"arithmetic_analysis/newton_raphson.py" = ["PGH001"]
9595
"audio_filters/show_response.py" = ["ARG002"]
9696
"data_structures/binary_tree/binary_search_tree_recursive.py" = ["BLE001"]
@@ -110,7 +110,7 @@ max-complexity = 17 # default: 10
110110
"project_euler/problem_099/sol1.py" = ["SIM115"]
111111
"sorts/external_sort.py" = ["SIM115"]
112112

113-
[tool.ruff.pylint] # DO NOT INCREASE THESE VALUES
113+
[tool.ruff.lint.pylint] # DO NOT INCREASE THESE VALUES
114114
allow-magic-value-types = ["float", "int", "str"]
115115
max-args = 10 # default: 5
116116
max-branches = 20 # default: 12

0 commit comments

Comments
 (0)