[pre-commit.ci] pre-commit autoupdate (#11275)

* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.1.14 → v0.2.0](https://github.com/astral-sh/ruff-pre-commit/compare/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 <cclauss@me.com>
This commit is contained in:
pre-commit-ci[bot] 2024-02-05 20:48:10 +01:00 committed by GitHub
parent 4128f19170
commit ed8d9209da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 25 additions and 39 deletions

View File

@ -16,7 +16,7 @@ repos:
- id: auto-walrus
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.14
rev: v0.2.0
hooks:
- id: ruff
- id: ruff-format

View File

@ -67,7 +67,7 @@ def mixed_keyword(
if verbose:
print(mapping)
# create the encrypted text by mapping the plaintext to the modified alphabet
return "".join(mapping[char] if char in mapping else char for char in plaintext)
return "".join(mapping.get(char, char) for char in plaintext)
if __name__ == "__main__":

View File

@ -22,7 +22,7 @@ unitlist = (
+ [cross(rs, cs) for rs in ("ABC", "DEF", "GHI") for cs in ("123", "456", "789")]
)
units = {s: [u for u in unitlist if s in u] for s in squares}
peers = {s: set(sum(units[s], [])) - {s} for s in squares}
peers = {s: set(sum(units[s], [])) - {s} for s in squares} # noqa: RUF017
def test():

View File

@ -171,11 +171,9 @@ def is_palindrome_dict(head: ListNode | None) -> bool:
if len(v) % 2 != 0:
middle += 1
else:
step = 0
for i in range(len(v)):
for step, i in enumerate(range(len(v))):
if v[i] + v[len(v) - 1 - step] != checksum:
return False
step += 1
if middle > 1:
return False
return True

View File

@ -22,11 +22,9 @@ def gaussian_filter(image, k_size, sigma):
# im2col, turn the k_size*k_size pixels into a row and np.vstack all rows
image_array = zeros((dst_height * dst_width, k_size * k_size))
row = 0
for i, j in product(range(dst_height), range(dst_width)):
for row, (i, j) in enumerate(product(range(dst_height), range(dst_width))):
window = ravel(image[i : i + k_size, j : j + k_size])
image_array[row, :] = window
row += 1
# turn the kernel into shape(k*k, 1)
gaussian_kernel = gen_gaussian_kernel(k_size, sigma)

View File

@ -20,13 +20,11 @@ def resistor_parallel(resistors: list[float]) -> float:
"""
first_sum = 0.00
index = 0
for resistor in resistors:
for index, resistor in enumerate(resistors):
if resistor <= 0:
msg = f"Resistor at index {index} has a negative or zero value!"
raise ValueError(msg)
first_sum += 1 / float(resistor)
index += 1
return 1 / first_sum
@ -44,13 +42,11 @@ def resistor_series(resistors: list[float]) -> float:
ValueError: Resistor at index 2 has a negative value!
"""
sum_r = 0.00
index = 0
for resistor in resistors:
for index, resistor in enumerate(resistors):
sum_r += resistor
if resistor < 0:
msg = f"Resistor at index {index} has a negative value!"
raise ValueError(msg)
index += 1
return sum_r

View File

@ -123,8 +123,7 @@ def emitter_converter(size_par, data):
# Bit counter one for a given parity
cont_bo = 0
# counter to control the loop reading
cont_loop = 0
for x in data_ord:
for cont_loop, x in enumerate(data_ord):
if x is not None:
try:
aux = (bin_pos[cont_loop])[-1 * (bp)]
@ -132,7 +131,6 @@ def emitter_converter(size_par, data):
aux = "0"
if aux == "1" and x == "1":
cont_bo += 1
cont_loop += 1
parity.append(cont_bo % 2)
qtd_bp += 1
@ -164,10 +162,10 @@ def receptor_converter(size_par, data):
parity_received = []
data_output = []
for x in range(1, len(data) + 1):
for i, item in enumerate(data, 1):
# Performs a template of bit positions - who should be given,
# and who should be parity
if qtd_bp < size_par and (np.log(x) / np.log(2)).is_integer():
if qtd_bp < size_par and (np.log(i) / np.log(2)).is_integer():
data_out_gab.append("P")
qtd_bp = qtd_bp + 1
else:
@ -175,10 +173,9 @@ def receptor_converter(size_par, data):
# Sorts the data to the new output size
if data_out_gab[-1] == "D":
data_output.append(data[cont_data])
data_output.append(item)
else:
parity_received.append(data[cont_data])
cont_data += 1
parity_received.append(item)
# -----------calculates the parity with the data
data_out = []
@ -215,9 +212,7 @@ def receptor_converter(size_par, data):
for bp in range(1, size_par + 1):
# Bit counter one for a certain parity
cont_bo = 0
# Counter to control loop reading
cont_loop = 0
for x in data_ord:
for cont_loop, x in enumerate(data_ord):
if x is not None:
try:
aux = (bin_pos[cont_loop])[-1 * (bp)]
@ -225,7 +220,6 @@ def receptor_converter(size_par, data):
aux = "0"
if aux == "1" and x == "1":
cont_bo += 1
cont_loop += 1
parity.append(str(cont_bo % 2))
qtd_bp += 1

View File

@ -237,7 +237,7 @@ def report_generator(
[
("sum", "sum"),
("mean_with_zeros", lambda x: np.mean(np.nan_to_num(x))),
("mean_without_zeros", lambda x: x.replace(0, np.NaN).mean()),
("mean_without_zeros", lambda x: x.replace(0, np.nan).mean()),
(
"mean_25-75",
lambda x: np.mean(

View File

@ -589,7 +589,7 @@ def plot_partition_boundary(
ax.contour(
xrange,
yrange,
np.mat(grid).T,
np.asmatrix(grid).T,
levels=(-1, 0, 1),
linestyles=("--", "-", "--"),
linewidths=(1, 1, 1),

View File

@ -41,11 +41,11 @@ class CNN:
self.rate_weight = rate_w
self.rate_thre = rate_t
self.w_conv1 = [
np.mat(-1 * np.random.rand(self.conv1[0], self.conv1[0]) + 0.5)
np.asmatrix(-1 * np.random.rand(self.conv1[0], self.conv1[0]) + 0.5)
for i in range(self.conv1[1])
]
self.wkj = np.mat(-1 * np.random.rand(self.num_bp3, self.num_bp2) + 0.5)
self.vji = np.mat(-1 * np.random.rand(self.num_bp2, self.num_bp1) + 0.5)
self.wkj = np.asmatrix(-1 * np.random.rand(self.num_bp3, self.num_bp2) + 0.5)
self.vji = np.asmatrix(-1 * np.random.rand(self.num_bp2, self.num_bp1) + 0.5)
self.thre_conv1 = -2 * np.random.rand(self.conv1[1]) + 1
self.thre_bp2 = -2 * np.random.rand(self.num_bp2) + 1
self.thre_bp3 = -2 * np.random.rand(self.num_bp3) + 1

View File

@ -1,5 +1,5 @@
[tool.ruff]
ignore = [ # `ruff rule S101` for a description of that rule
lint.ignore = [ # `ruff rule S101` for a description of that rule
"ARG001", # Unused function argument `amount` -- FIX ME?
"B904", # Within an `except` clause, raise exceptions with `raise ... from err` -- FIX ME
"B905", # `zip()` without an explicit `strict=` parameter -- FIX ME
@ -31,7 +31,7 @@ ignore = [ # `ruff rule S101` for a description of that rule
"SLF001", # Private member accessed: `_Iterator` -- FIX ME
"UP038", # Use `X | Y` in `{}` call instead of `(X, Y)` -- DO NOT FIX
]
select = [ # https://beta.ruff.rs/docs/rules
lint.select = [ # https://beta.ruff.rs/docs/rules
"A", # flake8-builtins
"ARG", # flake8-unused-arguments
"ASYNC", # flake8-async
@ -84,13 +84,13 @@ select = [ # https://beta.ruff.rs/docs/rules
# "TCH", # flake8-type-checking
# "TRY", # tryceratops
]
show-source = true
target-version = "py311"
output-format = "full"
target-version = "py312"
[tool.ruff.mccabe] # DO NOT INCREASE THIS VALUE
[tool.ruff.lint.mccabe] # DO NOT INCREASE THIS VALUE
max-complexity = 17 # default: 10
[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"arithmetic_analysis/newton_raphson.py" = ["PGH001"]
"audio_filters/show_response.py" = ["ARG002"]
"data_structures/binary_tree/binary_search_tree_recursive.py" = ["BLE001"]
@ -110,7 +110,7 @@ max-complexity = 17 # default: 10
"project_euler/problem_099/sol1.py" = ["SIM115"]
"sorts/external_sort.py" = ["SIM115"]
[tool.ruff.pylint] # DO NOT INCREASE THESE VALUES
[tool.ruff.lint.pylint] # DO NOT INCREASE THESE VALUES
allow-magic-value-types = ["float", "int", "str"]
max-args = 10 # default: 5
max-branches = 20 # default: 12