Enable ruff SIM102 rule (#11341)

* Enable ruff SIM102 rule

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

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

* Fix

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

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

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Maxim Smolskiy 2024-04-02 04:27:56 +03:00 committed by GitHub
parent f8a948914b
commit 93fb555e0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 73 additions and 50 deletions

View File

@ -92,9 +92,8 @@ def eliminate(values, s, d):
dplaces = [s for s in u if d in values[s]] dplaces = [s for s in u if d in values[s]]
if len(dplaces) == 0: if len(dplaces) == 0:
return False ## Contradiction: no place for this value return False ## Contradiction: no place for this value
elif len(dplaces) == 1:
# d can only be in one place in unit; assign it there # d can only be in one place in unit; assign it there
if not assign(values, dplaces[0], d): elif len(dplaces) == 1 and not assign(values, dplaces[0], d):
return False return False
return values return values

View File

@ -19,8 +19,9 @@ def balanced_parentheses(parentheses: str) -> bool:
for bracket in parentheses: for bracket in parentheses:
if bracket in bracket_pairs: if bracket in bracket_pairs:
stack.push(bracket) stack.push(bracket)
elif bracket in (")", "]", "}"): elif bracket in (")", "]", "}") and (
if stack.is_empty() or bracket_pairs[stack.pop()] != bracket: stack.is_empty() or bracket_pairs[stack.pop()] != bracket
):
return False return False
return stack.is_empty() return stack.is_empty()

View File

@ -75,8 +75,14 @@ def search(
for i in range(len(DIRECTIONS)): # to try out different valid actions for i in range(len(DIRECTIONS)): # to try out different valid actions
x2 = x + DIRECTIONS[i][0] x2 = x + DIRECTIONS[i][0]
y2 = y + DIRECTIONS[i][1] y2 = y + DIRECTIONS[i][1]
if x2 >= 0 and x2 < len(grid) and y2 >= 0 and y2 < len(grid[0]): if (
if closed[x2][y2] == 0 and grid[x2][y2] == 0: x2 >= 0
and x2 < len(grid)
and y2 >= 0
and y2 < len(grid[0])
and closed[x2][y2] == 0
and grid[x2][y2] == 0
):
g2 = g + cost g2 = g + cost
f2 = g2 + heuristic[x2][y2] f2 = g2 + heuristic[x2][y2]
cell.append([f2, g2, x2, y2]) cell.append([f2, g2, x2, y2])

View File

@ -36,8 +36,10 @@ def pass_and_relaxation(
queue.put((new_cost_f, nxt)) queue.put((new_cost_f, nxt))
cst_fwd[nxt] = new_cost_f cst_fwd[nxt] = new_cost_f
parent[nxt] = v parent[nxt] = v
if nxt in visited_backward: if (
if cst_fwd[v] + d + cst_bwd[nxt] < shortest_distance: nxt in visited_backward
and cst_fwd[v] + d + cst_bwd[nxt] < shortest_distance
):
shortest_distance = cst_fwd[v] + d + cst_bwd[nxt] shortest_distance = cst_fwd[v] + d + cst_bwd[nxt]
return shortest_distance return shortest_distance

View File

@ -64,9 +64,8 @@ class Clause:
value = model[symbol] value = model[symbol]
else: else:
continue continue
if value is not None:
# Complement assignment if literal is in complemented form # Complement assignment if literal is in complemented form
if literal.endswith("'"): if value is not None and literal.endswith("'"):
value = not value value = not value
self.literals[literal] = value self.literals[literal] = value

View File

@ -44,8 +44,12 @@ def fraction_list(digit_len: int) -> list[str]:
last_digit = int("1" + "0" * digit_len) last_digit = int("1" + "0" * digit_len)
for num in range(den, last_digit): for num in range(den, last_digit):
while den <= 99: while den <= 99:
if (num != den) and (num % 10 == den // 10) and (den % 10 != 0): if (
if is_digit_cancelling(num, den): (num != den)
and (num % 10 == den // 10)
and (den % 10 != 0)
and is_digit_cancelling(num, den)
):
solutions.append(f"{num}/{den}") solutions.append(f"{num}/{den}")
den += 1 den += 1
num += 1 num += 1

View File

@ -85,8 +85,9 @@ def validate(n: int) -> bool:
>>> validate(3797) >>> validate(3797)
True True
""" """
if len(str(n)) > 3: if len(str(n)) > 3 and (
if not is_prime(int(str(n)[-3:])) or not is_prime(int(str(n)[:3])): not is_prime(int(str(n)[-3:])) or not is_prime(int(str(n)[:3]))
):
return False return False
return True return True

View File

@ -81,8 +81,9 @@ class Graph:
while len(subgraph.vertices) < len(self.vertices): while len(subgraph.vertices) < len(self.vertices):
min_weight = max(self.edges.values()) + 1 min_weight = max(self.edges.values()) + 1
for edge, weight in self.edges.items(): for edge, weight in self.edges.items():
if (edge[0] in subgraph.vertices) ^ (edge[1] in subgraph.vertices): if (edge[0] in subgraph.vertices) ^ (
if weight < min_weight: edge[1] in subgraph.vertices
) and weight < min_weight:
min_edge = edge min_edge = edge
min_weight = weight min_weight = weight

View File

@ -88,8 +88,10 @@ def solution(max_proportion: float = 1 / 12345) -> int:
total_partitions += 1 total_partitions += 1
if check_partition_perfect(partition_candidate): if check_partition_perfect(partition_candidate):
perfect_partitions += 1 perfect_partitions += 1
if perfect_partitions > 0: if (
if perfect_partitions / total_partitions < max_proportion: perfect_partitions > 0
and perfect_partitions / total_partitions < max_proportion
):
return int(partition_candidate) return int(partition_candidate)
integer += 1 integer += 1

View File

@ -18,7 +18,6 @@ lint.ignore = [ # `ruff rule S101` for a description of that rule
"S105", # Possible hardcoded password: 'password' "S105", # Possible hardcoded password: 'password'
"S113", # Probable use of requests call without timeout -- FIX ME "S113", # Probable use of requests call without timeout -- FIX ME
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes -- FIX ME "S311", # Standard pseudo-random generators are not suitable for cryptographic purposes -- FIX ME
"SIM102", # Use a single `if` statement instead of nested `if` statements -- FIX ME
"SLF001", # Private member accessed: `_Iterator` -- FIX ME "SLF001", # Private member accessed: `_Iterator` -- FIX ME
"UP038", # Use `X | Y` in `{}` call instead of `(X, Y)` -- DO NOT FIX "UP038", # Use `X | Y` in `{}` call instead of `(X, Y)` -- DO NOT FIX
] ]

View File

@ -37,8 +37,11 @@ def calculate_waitingtime(
# Process until all processes are completed # Process until all processes are completed
while complete != no_of_processes: while complete != no_of_processes:
for j in range(no_of_processes): for j in range(no_of_processes):
if arrival_time[j] <= increment_time and remaining_time[j] > 0: if (
if remaining_time[j] < minm: arrival_time[j] <= increment_time
and remaining_time[j] > 0
and remaining_time[j] < minm
):
minm = remaining_time[j] minm = remaining_time[j]
short = j short = j
check = True check = True

View File

@ -71,9 +71,12 @@ def added_solution_file_path() -> list[pathlib.Path]:
def collect_solution_file_paths() -> list[pathlib.Path]: def collect_solution_file_paths() -> list[pathlib.Path]:
if os.environ.get("CI") and os.environ.get("GITHUB_EVENT_NAME") == "pull_request":
# Return only if there are any, otherwise default to all solutions # Return only if there are any, otherwise default to all solutions
if filepaths := added_solution_file_path(): if (
os.environ.get("CI")
and os.environ.get("GITHUB_EVENT_NAME") == "pull_request"
and (filepaths := added_solution_file_path())
):
return filepaths return filepaths
return all_solution_file_paths() return all_solution_file_paths()

View File

@ -30,10 +30,13 @@ class Parser(HTMLParser):
if tag == "a": if tag == "a":
# Check the list of defined attributes. # Check the list of defined attributes.
for name, value in attrs: for name, value in attrs:
# If href is defined, and not empty nor # print it. # If href is defined, not empty nor # print it and not already in urls.
if name == "href" and value != "#" and value != "": if (
# If not already in urls. name == "href"
if value not in self.urls: and value != "#"
and value != ""
and value not in self.urls
):
url = parse.urljoin(self.domain, value) url = parse.urljoin(self.domain, value)
self.urls.append(url) self.urls.append(url)