Skip to content

Commit 64543fa

Browse files
authored
Make some ruff fixes (#8154)
* Make some ruff fixes * Undo manual fix * Undo manual fix * Updates from ruff=0.0.251
1 parent 1c15cdf commit 64543fa

File tree

73 files changed

+151
-203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+151
-203
lines changed

audio_filters/iir_filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def set_coefficients(self, a_coeffs: list[float], b_coeffs: list[float]) -> None
4747
>>> filt.set_coefficients(a_coeffs, b_coeffs)
4848
"""
4949
if len(a_coeffs) < self.order:
50-
a_coeffs = [1.0] + a_coeffs
50+
a_coeffs = [1.0, *a_coeffs]
5151

5252
if len(a_coeffs) != self.order + 1:
5353
raise ValueError(

backtracking/n_queens_math.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ def depth_first_search(
129129

130130
# If it is False we call dfs function again and we update the inputs
131131
depth_first_search(
132-
possible_board + [col],
133-
diagonal_right_collisions + [row - col],
134-
diagonal_left_collisions + [row + col],
132+
[*possible_board, col],
133+
[*diagonal_right_collisions, row - col],
134+
[*diagonal_left_collisions, row + col],
135135
boards,
136136
n,
137137
)

backtracking/sum_of_subsets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def create_state_space_tree(
4444
nums,
4545
max_sum,
4646
index + 1,
47-
path + [nums[index]],
47+
[*path, nums[index]],
4848
result,
4949
remaining_nums_sum - nums[index],
5050
)

ciphers/bifid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def letter_to_numbers(self, letter: str) -> np.ndarray:
3333
>>> np.array_equal(BifidCipher().letter_to_numbers('u'), [4,5])
3434
True
3535
"""
36-
index1, index2 = np.where(self.SQUARE == letter)
36+
index1, index2 = np.where(letter == self.SQUARE)
3737
indexes = np.concatenate([index1 + 1, index2 + 1])
3838
return indexes
3939

ciphers/diffie_hellman.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,10 @@ def generate_public_key(self) -> str:
228228

229229
def is_valid_public_key(self, key: int) -> bool:
230230
# check if the other public key is valid based on NIST SP800-56
231-
if 2 <= key and key <= self.prime - 2:
232-
if pow(key, (self.prime - 1) // 2, self.prime) == 1:
233-
return True
234-
return False
231+
return (
232+
2 <= key <= self.prime - 2
233+
and pow(key, (self.prime - 1) // 2, self.prime) == 1
234+
)
235235

236236
def generate_shared_key(self, other_key_str: str) -> str:
237237
other_key = int(other_key_str, base=16)
@@ -243,10 +243,10 @@ def generate_shared_key(self, other_key_str: str) -> str:
243243
@staticmethod
244244
def is_valid_public_key_static(remote_public_key_str: int, prime: int) -> bool:
245245
# check if the other public key is valid based on NIST SP800-56
246-
if 2 <= remote_public_key_str and remote_public_key_str <= prime - 2:
247-
if pow(remote_public_key_str, (prime - 1) // 2, prime) == 1:
248-
return True
249-
return False
246+
return (
247+
2 <= remote_public_key_str <= prime - 2
248+
and pow(remote_public_key_str, (prime - 1) // 2, prime) == 1
249+
)
250250

251251
@staticmethod
252252
def generate_shared_key_static(

ciphers/polybius.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def letter_to_numbers(self, letter: str) -> np.ndarray:
3131
>>> np.array_equal(PolybiusCipher().letter_to_numbers('u'), [4,5])
3232
True
3333
"""
34-
index1, index2 = np.where(self.SQUARE == letter)
34+
index1, index2 = np.where(letter == self.SQUARE)
3535
indexes = np.concatenate([index1 + 1, index2 + 1])
3636
return indexes
3737

ciphers/xor_cipher.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,10 @@ def encrypt_file(self, file: str, key: int = 0) -> bool:
128128
assert isinstance(file, str) and isinstance(key, int)
129129

130130
try:
131-
with open(file) as fin:
132-
with open("encrypt.out", "w+") as fout:
133-
# actual encrypt-process
134-
for line in fin:
135-
fout.write(self.encrypt_string(line, key))
131+
with open(file) as fin, open("encrypt.out", "w+") as fout:
132+
# actual encrypt-process
133+
for line in fin:
134+
fout.write(self.encrypt_string(line, key))
136135

137136
except OSError:
138137
return False
@@ -152,11 +151,10 @@ def decrypt_file(self, file: str, key: int) -> bool:
152151
assert isinstance(file, str) and isinstance(key, int)
153152

154153
try:
155-
with open(file) as fin:
156-
with open("decrypt.out", "w+") as fout:
157-
# actual encrypt-process
158-
for line in fin:
159-
fout.write(self.decrypt_string(line, key))
154+
with open(file) as fin, open("decrypt.out", "w+") as fout:
155+
# actual encrypt-process
156+
for line in fin:
157+
fout.write(self.decrypt_string(line, key))
160158

161159
except OSError:
162160
return False

computer_vision/mosaic_augmentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def update_image_and_anno(
159159
new_anno.append([bbox[0], xmin, ymin, xmax, ymax])
160160

161161
# Remove bounding box small than scale of filter
162-
if 0 < filter_scale:
162+
if filter_scale > 0:
163163
new_anno = [
164164
anno
165165
for anno in new_anno

data_structures/binary_tree/binary_search_tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __insert(self, value) -> None:
6060
else: # Tree is not empty
6161
parent_node = self.root # from root
6262
if parent_node is None:
63-
return None
63+
return
6464
while True: # While we don't get to a leaf
6565
if value < parent_node.value: # We go left
6666
if parent_node.left is None:

data_structures/binary_tree/binary_tree_traversals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def preorder(root: Node | None) -> list[int]:
3737
>>> preorder(make_tree())
3838
[1, 2, 4, 5, 3]
3939
"""
40-
return [root.data] + preorder(root.left) + preorder(root.right) if root else []
40+
return [root.data, *preorder(root.left), *preorder(root.right)] if root else []
4141

4242

4343
def postorder(root: Node | None) -> list[int]:
@@ -55,7 +55,7 @@ def inorder(root: Node | None) -> list[int]:
5555
>>> inorder(make_tree())
5656
[4, 2, 5, 1, 3]
5757
"""
58-
return inorder(root.left) + [root.data] + inorder(root.right) if root else []
58+
return [*inorder(root.left), root.data, *inorder(root.right)] if root else []
5959

6060

6161
def height(root: Node | None) -> int:

0 commit comments

Comments
 (0)