Skip to content

Commit 7bd1e98

Browse files
authored
ruff rules RET for return statements (#15301)
* updating DIRECTORY.md * ruff rules RET for return statements --------- Co-authored-by: cclauss <cclauss@users.noreply.github.com>
1 parent a11c636 commit 7bd1e98

52 files changed

Lines changed: 163 additions & 191 deletions

Some content is hidden

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

‎.pre-commit-config.yaml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ repos:
3434
- id: pyproject-fmt
3535

3636
- repo: https://github.com/astral-sh/ruff-pre-commit
37-
rev: v0.16.6
37+
rev: v0.16.7
3838
hooks:
3939
- id: ruff-check
4040
- id: ruff-format
4141

4242
- repo: https://github.com/rvben/rumdl-pre-commit
43-
rev: v0.2.69
43+
rev: v0.2.73
4444
hooks:
4545
- id: rumdl-fmt
4646
- id: rumdl
@@ -55,7 +55,7 @@ repos:
5555
pass_filenames: false
5656

5757
- repo: https://github.com/astral-sh/uv-pre-commit
58-
rev: 0.12.11
58+
rev: 0.12.13
5959
hooks:
6060
- id: uv-lock
6161

‎DIRECTORY.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,7 @@
13721372
## [Sorts](sorts)
13731373
* [Adaptive Merge Sort](sorts/adaptive_merge_sort.py)
13741374
* [Bead Sort](sorts/bead_sort.py)
1375+
* [Benchmark Sorts](sorts/benchmark_sorts.py)
13751376
* [Binary Insertion Sort](sorts/binary_insertion_sort.py)
13761377
* [Bitonic Sort](sorts/bitonic_sort.py)
13771378
* [Bogo Sort](sorts/bogo_sort.py)

‎bit_manipulation/binary_count_setbits.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def binary_count_setbits(a: int) -> int:
3030
"""
3131
if a < 0:
3232
raise ValueError("Input value must be a positive integer")
33-
elif isinstance(a, float):
33+
if isinstance(a, float):
3434
raise TypeError("Input value must be a 'int' type")
3535
return bin(a).count("1")
3636

‎bit_manipulation/binary_count_trailing_zeros.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def binary_count_trailing_zeros(a: int) -> int:
3333
"""
3434
if a < 0:
3535
raise ValueError("Input value must be a positive integer")
36-
elif isinstance(a, float):
36+
if isinstance(a, float):
3737
raise TypeError("Input value must be a 'int' type")
3838
return 0 if (a == 0) else int(log2(a & -a))
3939

‎ciphers/enigma_machine2.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ def _plugboard(pbstring: str) -> dict[str, str]:
134134
if not isinstance(pbstring, str):
135135
msg = f"Plugboard setting isn't type string ({type(pbstring)})"
136136
raise TypeError(msg)
137-
elif len(pbstring) % 2 != 0:
137+
if len(pbstring) % 2 != 0:
138138
msg = f"Odd number of symbols ({len(pbstring)})"
139139
raise Exception(msg)
140-
elif pbstring == "":
140+
if pbstring == "":
141141
return {}
142142

143143
pbstring.replace(" ", "")
@@ -148,11 +148,10 @@ def _plugboard(pbstring: str) -> dict[str, str]:
148148
if i not in abc:
149149
msg = f"'{i}' not in list of symbols"
150150
raise Exception(msg)
151-
elif i in tmppbl:
151+
if i in tmppbl:
152152
msg = f"Duplicate symbol ({i})"
153153
raise Exception(msg)
154-
else:
155-
tmppbl.add(i)
154+
tmppbl.add(i)
156155
del tmppbl
157156

158157
# Created the dictionary

‎data_structures/binary_tree/binary_search_tree.py‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ def __insert(self, value) -> None:
183183
if parent_node.left is None:
184184
parent_node.left = new_node # We insert the new node in a leaf
185185
break
186-
else:
187-
parent_node = parent_node.left
186+
parent_node = parent_node.left
188187
elif parent_node.right is None:
189188
parent_node.right = new_node
190189
break
@@ -224,12 +223,11 @@ def search(self, value) -> Node | None:
224223

225224
if self.empty():
226225
raise IndexError("Warning: Tree is empty! please use another.")
227-
else:
228-
node = self.root
229-
# use lazy evaluation here to avoid NoneType Attribute error
230-
while node is not None and node.value is not value:
231-
node = node.left if value < node.value else node.right
232-
return node
226+
node = self.root
227+
# use lazy evaluation here to avoid NoneType Attribute error
228+
while node is not None and node.value is not value:
229+
node = node.left if value < node.value else node.right
230+
return node
233231

234232
def get_max(self, node: Node | None = None) -> Node | None:
235233
"""

‎data_structures/binary_tree/binary_search_tree_recursive.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def _search(self, node: Node | None, label: int) -> Node:
105105
if node is None:
106106
msg = f"Node with label {label} does not exist"
107107
raise ValueError(msg)
108-
elif label < node.label:
108+
if label < node.label:
109109
node = self._search(node.left, label)
110110
elif label > node.label:
111111
node = self._search(node.right, label)

‎data_structures/hashing/double_hash.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ def _collision_resolution(self, key, data=None):
7474
)
7575
if new_key is None:
7676
break
77-
else:
78-
i += 1
77+
i += 1
7978

8079
return new_key
8180

‎data_structures/linked_list/doubly_linked_list_two.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ def __iter__(self):
3535
def __next__(self):
3636
if not self.current:
3737
raise StopIteration
38-
else:
39-
value = self.current.data
40-
self.current = self.current.next
41-
return value
38+
value = self.current.data
39+
self.current = self.current.next
40+
return value
4241

4342

4443
@dataclass

‎data_structures/queues/priority_queue_using_list.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,9 @@ def dequeue(self) -> int:
165165
"""
166166
if not self.queue:
167167
raise UnderFlowError("The queue is empty")
168-
else:
169-
data = min(self.queue)
170-
self.queue.remove(data)
171-
return data
168+
data = min(self.queue)
169+
self.queue.remove(data)
170+
return data
172171

173172
def __str__(self) -> str:
174173
"""

0 commit comments

Comments
 (0)