Skip to content

Commit 8fe7311

Browse files
committed
Make the requested changes
Requested by @dhruvmanila
1 parent a9cf143 commit 8fe7311

File tree

13 files changed

+20
-37
lines changed

13 files changed

+20
-37
lines changed

data_structures/stacks/stack.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ def test_stack() -> None:
110110
assert not stack.is_empty()
111111
assert stack.is_full()
112112
assert str(stack) == str(list(range(10)))
113-
test = stack.pop()
114-
assert test == 9
113+
assert stack.pop() == 9
115114
assert stack.peek() == 8
116115

117116
stack.push(100)

fuzzy_logic/fuzzy_operations.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@
99
"""
1010
import numpy as np
1111

12-
try:
13-
import skfuzzy as fuzz
14-
except ImportError:
15-
import sys
16-
17-
sys.exit() # This is so the CI doesn't complain about an unknown library
12+
import skfuzzy as fuzz
1813

1914
if __name__ == "__main__":
2015
# Create universe of discourse in Python using linspace ()

graphs/directed_and_undirected_(weighted)_graph.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,6 @@ def has_cycle(self):
225225
anticipating_nodes.add(node[1])
226226
break
227227
else:
228-
# FIXME: there used to be unreachable code here.
229-
# Code removed because of linter complaints.
230228
return True
231229
if visited.count(node[1]) < 1:
232230
stack.append(node[1])
@@ -452,8 +450,6 @@ def has_cycle(self):
452450
anticipating_nodes.add(node[1])
453451
break
454452
else:
455-
# FIXME: there used to be unreachable code here.
456-
# Code removed because of linter complaints.
457453
return True
458454
if visited.count(node[1]) < 1:
459455
stack.append(node[1])

hashes/hamming_code.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ def emitterConverter(sizePar, data):
7979
['1', '1', '1', '1', '0', '1', '0', '0', '1', '0', '1', '1', '1', '1', '1', '1']
8080
"""
8181
if sizePar + len(data) <= 2**sizePar - (len(data) - 1):
82-
print("ERROR - size of parity don't match with size of data")
83-
import sys
84-
85-
sys.exit(0)
82+
raise ValueError("ERROR - size of parity don't match with size of data")
8683

8784
dataOut = []
8885
parity = []

maths/extended_euclidean_algorithm.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ def main():
7575
"""Call Extended Euclidean Algorithm."""
7676
if len(sys.argv) < 3:
7777
print("2 integer arguments required")
78-
sys.exit(1)
78+
return 1
7979
a = int(sys.argv[1])
8080
b = int(sys.argv[2])
8181
print(extended_euclidean_algorithm(a, b))
82+
return 0
8283

8384

8485
if __name__ == "__main__":
85-
main()
86+
raise SystemExit(main())

matrix/matrix_class.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def add_column(self, column: list[int], position: int | None = None) -> None:
286286
# MATRIX OPERATIONS
287287
def __eq__(self, other: object) -> bool:
288288
if not isinstance(other, Matrix):
289-
return False
289+
return NotImplemented
290290
return self.rows == other.rows
291291

292292
def __ne__(self, other: object) -> bool:

other/lfu_cache.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ def set(self, key: T, value: U) -> None:
264264
# explain to type checker via assertions
265265
assert first_node is not None
266266
assert first_node.key is not None
267-
remove_test = self.list.remove(first_node)
268-
assert remove_test is not None
267+
assert self.list.remove(first_node) is not None
269268
# first_node guaranteed to be in list
270269

271270
del self.cache[first_node.key]

other/lru_cache.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,8 @@ def set(self, key: T, value: U) -> None:
280280
# explain to type checker via assertions
281281
assert first_node is not None
282282
assert first_node.key is not None
283-
test_removal = self.list.remove(first_node)
284283
assert (
285-
test_removal is not None
284+
self.list.remove(first_node) is not None
286285
) # node guaranteed to be in list assert node.key is not None
287286

288287
del self.cache[first_node.key]

project_euler/problem_067/sol1.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ def solution():
2828
with open(triangle) as f:
2929
triangle = f.readlines()
3030

31-
a = [x.rstrip("\r\n").split(" ") for x in triangle]
32-
a = [[int(i) for i in x] for x in a]
31+
a = []
32+
for line in triangle:
33+
numbers_from_line = []
34+
for number in line.strip().split(" "):
35+
numbers_from_line.append(int(number))
36+
a.append(numbers_from_line)
3337

3438
for i in range(1, len(a)):
3539
for j in range(len(a[i])):

project_euler/problem_099/sol1.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def solution(data_file: str = "base_exp.txt") -> int:
2525
largest: float = 0
2626
result = 0
2727
for i, line in enumerate(open(os.path.join(os.path.dirname(__file__), data_file))):
28-
a, x = line.split(",")
29-
a, x = int(a), int(x)
28+
a, x = list(map(int, line.split(",")))
3029
if x * log10(a) > largest:
3130
largest = x * log10(a)
3231
result = i + 1

scheduling/first_come_first_served.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,21 @@ def calculate_average_waiting_time(waiting_times: list[int]) -> float:
7373

7474

7575
if __name__ == "__main__":
76-
import sys
77-
7876
# process id's
7977
processes = [1, 2, 3]
8078

8179
# ensure that we actually have processes
8280
if len(processes) == 0:
8381
print("Zero amount of processes")
84-
sys.exit()
82+
raise SystemExit
8583

8684
# duration time of all processes
8785
duration_times = [19, 8, 9]
8886

8987
# ensure we can match each id to a duration time
9088
if len(duration_times) != len(processes):
9189
print("Unable to match all id's with their duration time")
92-
sys.exit()
90+
raise SystemExit
9391

9492
# get the waiting times and the turnaround times
9593
waiting_times = calculate_waiting_times(duration_times)

scheduling/multi_level_feedback_queue.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,7 @@ def multi_level_feedback_queue(self) -> deque[Process]:
276276
queue = deque([P1, P2, P3, P4])
277277

278278
if len(time_slices) != number_of_queues - 1:
279-
import sys
280-
281-
sys.exit()
279+
raise SystemExit
282280

283281
doctest.testmod(extraglobs={"queue": deque([P1, P2, P3, P4])})
284282

web_programming/emails_from_url.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ def emails_from_url(url: str = "https://github.com") -> list[str]:
9393
except ValueError:
9494
pass
9595
except ValueError:
96-
import sys
97-
98-
sys.exit(-1)
96+
raise SystemExit
9997

10098
# Finally return a sorted list of email addresses with no duplicates.
10199
return sorted(valid_emails)

0 commit comments

Comments
 (0)