diff --git a/ciphers/xor_cipher.py b/ciphers/xor_cipher.py index 24d88a0fd588..2196775cf575 100644 --- a/ciphers/xor_cipher.py +++ b/ciphers/xor_cipher.py @@ -21,7 +21,7 @@ class XORCipher: - def __init__(self, key: int = 0): + def __init__(self, key: int = 0) -> None: """ simple constructor that receives a key or uses default key = 0 diff --git a/computer_vision/harris_corner.py b/computer_vision/harris_corner.py index 0cc7522bc3af..c47ba2019c4f 100644 --- a/computer_vision/harris_corner.py +++ b/computer_vision/harris_corner.py @@ -8,7 +8,7 @@ class HarrisCorner: - def __init__(self, k: float, window_size: int): + def __init__(self, k: float, window_size: int) -> None: """ k : is an empirically determined constant in [0.04,0.06] window_size : neighbourhoods considered diff --git a/data_compression/huffman.py b/data_compression/huffman.py index 44eda6c03180..15bd311e4fc6 100644 --- a/data_compression/huffman.py +++ b/data_compression/huffman.py @@ -4,7 +4,7 @@ class Letter: - def __init__(self, letter: str, freq: int): + def __init__(self, letter: str, freq: int) -> None: self.letter: str = letter self.freq: int = freq self.bitstring: dict[str, str] = {} @@ -14,7 +14,9 @@ def __repr__(self) -> str: class TreeNode: - def __init__(self, freq: int, left: Letter | TreeNode, right: Letter | TreeNode): + def __init__( + self, freq: int, left: Letter | TreeNode, right: Letter | TreeNode + ) -> None: self.freq: int = freq self.left: Letter | TreeNode = left self.right: Letter | TreeNode = right diff --git a/data_structures/binary_tree/segment_tree.py b/data_structures/binary_tree/segment_tree.py index 084fcf84955d..42f48171bd3b 100644 --- a/data_structures/binary_tree/segment_tree.py +++ b/data_structures/binary_tree/segment_tree.py @@ -2,7 +2,7 @@ class SegmentTree: - def __init__(self, a): + def __init__(self, a) -> None: self.A = a self.N = len(self.A) self.st = [0] * ( diff --git a/data_structures/binary_tree/segment_tree_other.py b/data_structures/binary_tree/segment_tree_other.py index 95f21ddd4777..c491bc64d4df 100644 --- a/data_structures/binary_tree/segment_tree_other.py +++ b/data_structures/binary_tree/segment_tree_other.py @@ -9,7 +9,7 @@ class SegmentTreeNode: - def __init__(self, start, end, val, left=None, right=None): + def __init__(self, start, end, val, left=None, right=None) -> None: self.start = start self.end = end self.val = val @@ -17,7 +17,7 @@ def __init__(self, start, end, val, left=None, right=None): self.left = left self.right = right - def __repr__(self): + def __repr__(self) -> str: return f"SegmentTreeNode(start={self.start}, end={self.end}, val={self.val})" @@ -127,7 +127,7 @@ class SegmentTree: >>> """ - def __init__(self, collection: Sequence, function): + def __init__(self, collection: Sequence, function) -> None: self.collection = collection self.fn = function if self.collection: diff --git a/data_structures/binary_tree/treap.py b/data_structures/binary_tree/treap.py index 2aa341582701..24f8e365a516 100644 --- a/data_structures/binary_tree/treap.py +++ b/data_structures/binary_tree/treap.py @@ -9,7 +9,7 @@ class Node: Treap is a binary tree by value and heap by priority """ - def __init__(self, value: int | None = None): + def __init__(self, value: int | None = None) -> None: self.value = value self.prior = random() self.left: Node | None = None diff --git a/data_structures/hashing/double_hash.py b/data_structures/hashing/double_hash.py index 324282cbfd8d..dafbb04ba45d 100644 --- a/data_structures/hashing/double_hash.py +++ b/data_structures/hashing/double_hash.py @@ -21,7 +21,7 @@ class DoubleHash(HashTable): Hash Table example with open addressing and Double Hash """ - def __init__(self, *args, **kwargs): + def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) def __hash_function_2(self, value, data): diff --git a/data_structures/hashing/hash_table_with_linked_list.py b/data_structures/hashing/hash_table_with_linked_list.py index c8dffa30b8e8..174a231b2071 100644 --- a/data_structures/hashing/hash_table_with_linked_list.py +++ b/data_structures/hashing/hash_table_with_linked_list.py @@ -4,7 +4,7 @@ class HashTableWithLinkedList(HashTable): - def __init__(self, *args, **kwargs): + def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) def _set_value(self, key, data): diff --git a/data_structures/hashing/quadratic_probing.py b/data_structures/hashing/quadratic_probing.py index 56d4926eee9b..8d8b4457232a 100644 --- a/data_structures/hashing/quadratic_probing.py +++ b/data_structures/hashing/quadratic_probing.py @@ -8,7 +8,7 @@ class QuadraticProbing(HashTable): Basic Hash Table example with open addressing using Quadratic Probing """ - def __init__(self, *args, **kwargs): + def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) def _collision_resolution(self, key, data=None): # noqa: ARG002 diff --git a/data_structures/heap/binomial_heap.py b/data_structures/heap/binomial_heap.py index c97ec1c32149..cbe5bce99d2e 100644 --- a/data_structures/heap/binomial_heap.py +++ b/data_structures/heap/binomial_heap.py @@ -12,7 +12,7 @@ class Node: - link to left, right and parent nodes """ - def __init__(self, val): + def __init__(self, val) -> None: self.val = val # Number of nodes in left subtree self.left_tree_size = 0 @@ -123,7 +123,7 @@ class BinomialHeap: [17, 20, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 34] """ - def __init__(self, bottom_root=None, min_node=None, heap_size=0): + def __init__(self, bottom_root=None, min_node=None, heap_size=0) -> None: self.size = heap_size self.bottom_root = bottom_root self.min_node = min_node @@ -384,7 +384,7 @@ def __traversal(self, curr_node, preorder, level=0): else: preorder.append(("#", level)) - def __str__(self): + def __str__(self) -> str: """ Overwriting str for a pre-order print of nodes in heap; Performance is poor, so use only for small examples diff --git a/data_structures/heap/max_heap.py b/data_structures/heap/max_heap.py index 589f2595a8da..6fec29ba6d3b 100644 --- a/data_structures/heap/max_heap.py +++ b/data_structures/heap/max_heap.py @@ -16,7 +16,7 @@ class BinaryHeap: 2 """ - def __init__(self): + def __init__(self) -> None: self.__heap = [0] self.__size = 0 @@ -63,7 +63,7 @@ def pop(self) -> int: def get_list(self): return self.__heap[1:] - def __len__(self): + def __len__(self) -> int: """Length of the array""" return self.__size diff --git a/data_structures/heap/min_heap.py b/data_structures/heap/min_heap.py index 577b98d788a1..ee04b9ba071b 100644 --- a/data_structures/heap/min_heap.py +++ b/data_structures/heap/min_heap.py @@ -3,11 +3,11 @@ class Node: - def __init__(self, name, val): + def __init__(self, name, val) -> None: self.name = name self.val = val - def __str__(self): + def __str__(self) -> str: return f"{self.__class__.__name__}({self.name}, {self.val})" def __lt__(self, other): @@ -31,7 +31,7 @@ class MinHeap: -17 """ - def __init__(self, array): + def __init__(self, array) -> None: self.idx_of_element = {} self.heap_dict = {} self.heap = self.build_heap(array) diff --git a/data_structures/linked_list/deque_doubly.py b/data_structures/linked_list/deque_doubly.py index e554ead91c5a..18fb67cea825 100644 --- a/data_structures/linked_list/deque_doubly.py +++ b/data_structures/linked_list/deque_doubly.py @@ -14,7 +14,7 @@ class _DoublyLinkedBase: class _Node: __slots__ = "_data", "_next", "_prev" - def __init__(self, link_p, element, link_n): + def __init__(self, link_p, element, link_n) -> None: self._prev = link_p self._data = element self._next = link_n @@ -24,14 +24,14 @@ def has_next_and_prev(self): f" Prev -> {self._prev is not None}, Next -> {self._next is not None}" ) - def __init__(self): + def __init__(self) -> None: self._header = self._Node(None, None, None) self._trailer = self._Node(None, None, None) self._header._next = self._trailer self._trailer._prev = self._header self._size = 0 - def __len__(self): + def __len__(self) -> int: return self._size def is_empty(self): diff --git a/data_structures/linked_list/doubly_linked_list.py b/data_structures/linked_list/doubly_linked_list.py index 1eee15edf714..f79f0f8842bc 100644 --- a/data_structures/linked_list/doubly_linked_list.py +++ b/data_structures/linked_list/doubly_linked_list.py @@ -8,17 +8,17 @@ class Node: - def __init__(self, data: Any): + def __init__(self, data: Any) -> None: self.data = data self.previous: Node | None = None self.next: Node | None = None - def __str__(self): + def __str__(self) -> str: return f"{self.data}" class DoublyLinkedList: - def __init__(self): + def __init__(self) -> None: self.head: Node | None = None self.tail: Node | None = None @@ -36,7 +36,7 @@ def __iter__(self): yield node.data node = node.next - def __str__(self): + def __str__(self) -> str: """ >>> linked_list = DoublyLinkedList() >>> linked_list.insert_at_tail('a') @@ -47,7 +47,7 @@ def __str__(self): """ return "->".join([str(item) for item in self]) - def __len__(self): + def __len__(self) -> int: """ >>> linked_list = DoublyLinkedList() >>> for i in range(0, 5): diff --git a/data_structures/linked_list/doubly_linked_list_two.py b/data_structures/linked_list/doubly_linked_list_two.py index a7f639a6e289..dcf0166ee6db 100644 --- a/data_structures/linked_list/doubly_linked_list_two.py +++ b/data_structures/linked_list/doubly_linked_list_two.py @@ -26,7 +26,7 @@ def __str__(self) -> str: class LinkedListIterator: - def __init__(self, head): + def __init__(self, head) -> None: self.current = head def __iter__(self): @@ -46,7 +46,7 @@ class LinkedList: head: Node | None = None # First node in list tail: Node | None = None # Last node in list - def __str__(self): + def __str__(self) -> str: current = self.head nodes = [] while current is not None: @@ -54,7 +54,7 @@ def __str__(self): current = current.next return " ".join(str(node) for node in nodes) - def __contains__(self, value: DataType): + def __contains__(self, value: DataType) -> bool: current = self.head while current: if current.data == value: diff --git a/data_structures/linked_list/from_sequence.py b/data_structures/linked_list/from_sequence.py index b16b2258c1f1..c41b25b211e9 100644 --- a/data_structures/linked_list/from_sequence.py +++ b/data_structures/linked_list/from_sequence.py @@ -5,11 +5,11 @@ class Node: - def __init__(self, data=None): + def __init__(self, data=None) -> None: self.data = data self.next = None - def __repr__(self): + def __repr__(self) -> str: """Returns a visual representation of the node and all its following nodes.""" string_rep = "" temp = self diff --git a/data_structures/linked_list/middle_element_of_linked_list.py b/data_structures/linked_list/middle_element_of_linked_list.py index 86dad6b41d73..330193fef21e 100644 --- a/data_structures/linked_list/middle_element_of_linked_list.py +++ b/data_structures/linked_list/middle_element_of_linked_list.py @@ -8,7 +8,7 @@ def __init__(self, data: int) -> None: class LinkedList: - def __init__(self): + def __init__(self) -> None: self.head = None def push(self, new_data: int) -> int: diff --git a/data_structures/linked_list/singly_linked_list.py b/data_structures/linked_list/singly_linked_list.py index 3ec91242d62c..0733d07da95e 100644 --- a/data_structures/linked_list/singly_linked_list.py +++ b/data_structures/linked_list/singly_linked_list.py @@ -38,7 +38,7 @@ def __repr__(self) -> str: class LinkedList: - def __init__(self): + def __init__(self) -> None: """ Create and initialize LinkedList class instance. >>> linked_list = LinkedList() diff --git a/data_structures/linked_list/skip_list.py b/data_structures/linked_list/skip_list.py index f21ca70bbc82..3c2eed66065c 100644 --- a/data_structures/linked_list/skip_list.py +++ b/data_structures/linked_list/skip_list.py @@ -14,7 +14,7 @@ class Node[KT, VT]: - def __init__(self, key: KT | str = "root", value: VT | None = None): + def __init__(self, key: KT | str = "root", value: VT | None = None) -> None: self.key = key self.value = value self.forward: list[Node[KT, VT]] = [] @@ -50,7 +50,7 @@ def level(self) -> int: class SkipList[KT, VT]: - def __init__(self, p: float = 0.5, max_level: int = 16): + def __init__(self, p: float = 0.5, max_level: int = 16) -> None: self.head: Node[KT, VT] = Node[KT, VT]() self.level = 0 self.p = p diff --git a/data_structures/queues/circular_queue.py b/data_structures/queues/circular_queue.py index e9cb2cac4fd8..dc3ad8ba4390 100644 --- a/data_structures/queues/circular_queue.py +++ b/data_structures/queues/circular_queue.py @@ -4,7 +4,7 @@ class CircularQueue: """Circular FIFO queue with a fixed capacity""" - def __init__(self, n: int): + def __init__(self, n: int) -> None: self.n = n self.array = [None] * self.n self.front = 0 # index of the first element diff --git a/data_structures/queues/priority_queue_using_list.py b/data_structures/queues/priority_queue_using_list.py index 15e56c557069..59f63aa168d4 100644 --- a/data_structures/queues/priority_queue_using_list.py +++ b/data_structures/queues/priority_queue_using_list.py @@ -66,7 +66,7 @@ class FixedPriorityQueue: Priority 2: [] """ # noqa: E501 - def __init__(self): + def __init__(self) -> None: self.queues = [ [], [], @@ -146,7 +146,7 @@ class ElementPriorityQueue: [] """ - def __init__(self): + def __init__(self) -> None: self.queue = [] def enqueue(self, data: int) -> None: diff --git a/data_structures/queues/queue_on_pseudo_stack.py b/data_structures/queues/queue_on_pseudo_stack.py index 2da67ecc263c..95b84a309783 100644 --- a/data_structures/queues/queue_on_pseudo_stack.py +++ b/data_structures/queues/queue_on_pseudo_stack.py @@ -4,11 +4,11 @@ class Queue: - def __init__(self): + def __init__(self) -> None: self.stack = [] self.length = 0 - def __str__(self): + def __str__(self) -> str: printed = "<" + str(self.stack)[1:-1] + ">" return printed diff --git a/data_structures/stacks/stack.py b/data_structures/stacks/stack.py index 3ffa32d4167f..8de2f61085c9 100644 --- a/data_structures/stacks/stack.py +++ b/data_structures/stacks/stack.py @@ -22,7 +22,7 @@ class Stack[T]: https://en.wikipedia.org/wiki/Stack_(abstract_data_type) """ - def __init__(self, limit: int = 10): + def __init__(self, limit: int = 10) -> None: self.stack: list[T] = [] self.limit = limit diff --git a/data_structures/stacks/stack_with_doubly_linked_list.py b/data_structures/stacks/stack_with_doubly_linked_list.py index ad01cd7eb6aa..347ae8ec801c 100644 --- a/data_structures/stacks/stack_with_doubly_linked_list.py +++ b/data_structures/stacks/stack_with_doubly_linked_list.py @@ -9,7 +9,7 @@ class Node[T]: - def __init__(self, data: T): + def __init__(self, data: T) -> None: self.data = data # Assign data self.next: Node[T] | None = None # Initialize next as null self.prev: Node[T] | None = None # Initialize prev as null diff --git a/data_structures/stacks/stack_with_singly_linked_list.py b/data_structures/stacks/stack_with_singly_linked_list.py index 57a68679eee1..6257c33a4ee8 100644 --- a/data_structures/stacks/stack_with_singly_linked_list.py +++ b/data_structures/stacks/stack_with_singly_linked_list.py @@ -9,7 +9,7 @@ class Node[T]: - def __init__(self, data: T): + def __init__(self, data: T) -> None: self.data = data self.next: Node[T] | None = None diff --git a/digital_image_processing/dithering/burkes.py b/digital_image_processing/dithering/burkes.py index 4b59356d8f08..d9aa11849cc1 100644 --- a/digital_image_processing/dithering/burkes.py +++ b/digital_image_processing/dithering/burkes.py @@ -16,7 +16,7 @@ class Burkes: * This implementation get RGB image and converts it to greyscale in runtime. """ - def __init__(self, input_img, threshold: int): + def __init__(self, input_img, threshold: int) -> None: self.min_threshold = 0 # max greyscale value for #FFFFFF self.max_threshold = int(self.get_greyscale(255, 255, 255)) diff --git a/digital_image_processing/histogram_equalization/histogram_stretch.py b/digital_image_processing/histogram_equalization/histogram_stretch.py index 1270c964dee6..db36ed4fe1de 100644 --- a/digital_image_processing/histogram_equalization/histogram_stretch.py +++ b/digital_image_processing/histogram_equalization/histogram_stretch.py @@ -13,7 +13,7 @@ class ConstantStretch: - def __init__(self): + def __init__(self) -> None: self.img = "" self.original_image = "" self.last_list = [] diff --git a/digital_image_processing/index_calculation.py b/digital_image_processing/index_calculation.py index 988f8e72b9a8..d9151529d482 100644 --- a/digital_image_processing/index_calculation.py +++ b/digital_image_processing/index_calculation.py @@ -104,7 +104,9 @@ class IndexCalculation: #RGBIndex = ["GLI", "CI", "Hue", "I", "NGRDI", "RI", "S", "IF"] """ - def __init__(self, red=None, green=None, blue=None, red_edge=None, nir=None): + def __init__( + self, red=None, green=None, blue=None, red_edge=None, nir=None + ) -> None: self.set_matricies(red=red, green=green, blue=blue, red_edge=red_edge, nir=nir) def set_matricies(self, red=None, green=None, blue=None, red_edge=None, nir=None): diff --git a/digital_image_processing/resize/resize.py b/digital_image_processing/resize/resize.py index 7bde118da69b..dbbfd976d531 100644 --- a/digital_image_processing/resize/resize.py +++ b/digital_image_processing/resize/resize.py @@ -10,7 +10,7 @@ class NearestNeighbour: Source: https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation """ - def __init__(self, img, dst_width: int, dst_height: int): + def __init__(self, img, dst_width: int, dst_height: int) -> None: if dst_width < 0 or dst_height < 0: raise ValueError("Destination width/height should be > 0") diff --git a/divide_and_conquer/convex_hull.py b/divide_and_conquer/convex_hull.py index b1ab33cc9415..167046fefb36 100644 --- a/divide_and_conquer/convex_hull.py +++ b/divide_and_conquer/convex_hull.py @@ -45,7 +45,7 @@ class Point: ValueError: could not convert string to float: 'pi' """ - def __init__(self, x, y): + def __init__(self, x, y) -> None: self.x, self.y = float(x), float(y) def __eq__(self, other): @@ -78,7 +78,7 @@ def __le__(self, other): return self.y <= other.y return False - def __repr__(self): + def __repr__(self) -> str: return f"({self.x}, {self.y})" def __hash__(self): diff --git a/dynamic_programming/bitmask.py b/dynamic_programming/bitmask.py index 4737a3419e8e..1ea072e01e16 100644 --- a/dynamic_programming/bitmask.py +++ b/dynamic_programming/bitmask.py @@ -13,7 +13,7 @@ class AssignmentUsingBitmask: - def __init__(self, task_performed, total): + def __init__(self, task_performed, total) -> None: self.total_tasks = total # total no of tasks (N) # DP table will have a dimension of (2^M)*N diff --git a/dynamic_programming/edit_distance.py b/dynamic_programming/edit_distance.py index 774aa047326e..fa3a9ffd1390 100644 --- a/dynamic_programming/edit_distance.py +++ b/dynamic_programming/edit_distance.py @@ -18,7 +18,7 @@ class EditDistance: editDistanceResult = solver.solve(firstString, secondString) """ - def __init__(self): + def __init__(self) -> None: self.word1 = "" self.word2 = "" self.dp = [] diff --git a/dynamic_programming/floyd_warshall.py b/dynamic_programming/floyd_warshall.py index b92c6667fb5c..24fe251c8d83 100644 --- a/dynamic_programming/floyd_warshall.py +++ b/dynamic_programming/floyd_warshall.py @@ -2,7 +2,7 @@ class Graph: - def __init__(self, n=0): # a graph with Node 0,1,...,N-1 + def __init__(self, n=0) -> None: # a graph with Node 0,1,...,N-1 self.n = n self.w = [ [math.inf for j in range(n)] for i in range(n) diff --git a/dynamic_programming/optimal_binary_search_tree.py b/dynamic_programming/optimal_binary_search_tree.py index b4f1181ac11c..c1d4f87d68a6 100644 --- a/dynamic_programming/optimal_binary_search_tree.py +++ b/dynamic_programming/optimal_binary_search_tree.py @@ -23,11 +23,11 @@ class Node: """Binary Search Tree Node""" - def __init__(self, key, freq): + def __init__(self, key, freq) -> None: self.key = key self.freq = freq - def __str__(self): + def __str__(self) -> str: """ >>> str(Node(1, 2)) 'Node(key=1, freq=2)' diff --git a/graphics/bezier_curve.py b/graphics/bezier_curve.py index 03d1113cbb3f..0325382673a1 100644 --- a/graphics/bezier_curve.py +++ b/graphics/bezier_curve.py @@ -12,7 +12,7 @@ class BezierCurve: This implementation works only for 2d coordinates in the xy plane. """ - def __init__(self, list_of_points: list[tuple[float, float]]): + def __init__(self, list_of_points: list[tuple[float, float]]) -> None: """ list_of_points: Control points in the xy plane on which to interpolate. These points control the behavior (shape) of the Bezier curve. diff --git a/graphs/bidirectional_a_star.py b/graphs/bidirectional_a_star.py index 00f623de3493..498e87589c0a 100644 --- a/graphs/bidirectional_a_star.py +++ b/graphs/bidirectional_a_star.py @@ -91,7 +91,7 @@ class AStar: (4, 3), (4, 4), (5, 4), (5, 5), (6, 5), (6, 6)] """ - def __init__(self, start: TPosition, goal: TPosition): + def __init__(self, start: TPosition, goal: TPosition) -> None: self.start = Node(start[1], start[0], goal[1], goal[0], 0, None) self.target = Node(goal[1], goal[0], goal[1], goal[0], 99999, None) diff --git a/graphs/bidirectional_breadth_first_search.py b/graphs/bidirectional_breadth_first_search.py index 71c5a9aff08f..5740c3df65ac 100644 --- a/graphs/bidirectional_breadth_first_search.py +++ b/graphs/bidirectional_breadth_first_search.py @@ -24,7 +24,7 @@ class Node: def __init__( self, pos_x: int, pos_y: int, goal_x: int, goal_y: int, parent: Node | None - ): + ) -> None: self.pos_x = pos_x self.pos_y = pos_y self.pos = (pos_y, pos_x) @@ -52,7 +52,7 @@ class BreadthFirstSearch: (5, 1), (5, 2), (5, 3), (5, 4), (5, 5), (6, 5), (6, 6)] """ - def __init__(self, start: tuple[int, int], goal: tuple[int, int]): + def __init__(self, start: tuple[int, int], goal: tuple[int, int]) -> None: self.start = Node(start[1], start[0], goal[1], goal[0], None) self.target = Node(goal[1], goal[0], goal[1], goal[0], None) @@ -122,7 +122,7 @@ class BidirectionalBreadthFirstSearch: (2, 4), (3, 4), (3, 5), (3, 6), (4, 6), (5, 6), (6, 6)] """ - def __init__(self, start, goal): + def __init__(self, start, goal) -> None: self.fwd_bfs = BreadthFirstSearch(start, goal) self.bwd_bfs = BreadthFirstSearch(goal, start) self.reached = False diff --git a/graphs/breadth_first_search_zero_one_shortest_path.py b/graphs/breadth_first_search_zero_one_shortest_path.py index d3a255bac1ef..c0d9f8addf0b 100644 --- a/graphs/breadth_first_search_zero_one_shortest_path.py +++ b/graphs/breadth_first_search_zero_one_shortest_path.py @@ -22,7 +22,7 @@ class Edge: class AdjacencyList: """Graph adjacency list.""" - def __init__(self, size: int): + def __init__(self, size: int) -> None: self._graph: list[list[Edge]] = [[] for _ in range(size)] self._size = size diff --git a/graphs/depth_first_search_2.py b/graphs/depth_first_search_2.py index 8fe48b7f2b42..9c6add2a5151 100644 --- a/graphs/depth_first_search_2.py +++ b/graphs/depth_first_search_2.py @@ -4,7 +4,7 @@ class Graph: - def __init__(self): + def __init__(self) -> None: self.vertex = {} # for printing the Graph vertices diff --git a/graphs/dijkstra_algorithm.py b/graphs/dijkstra_algorithm.py index 60646862fca8..f1d9f4858e66 100644 --- a/graphs/dijkstra_algorithm.py +++ b/graphs/dijkstra_algorithm.py @@ -10,7 +10,7 @@ class PriorityQueue: # Based on Min Heap - def __init__(self): + def __init__(self) -> None: """ Priority queue class constructor method. @@ -211,7 +211,7 @@ def decrease_key(self, tup, new_d): class Graph: - def __init__(self, num): + def __init__(self, num) -> None: """ Graph class constructor diff --git a/graphs/dinic.py b/graphs/dinic.py index 7919e6bc060a..ef094c462603 100644 --- a/graphs/dinic.py +++ b/graphs/dinic.py @@ -2,7 +2,7 @@ class Dinic: - def __init__(self, n): + def __init__(self, n) -> None: self.lvl = [0] * n self.ptr = [0] * n self.q = [0] * n diff --git a/graphs/directed_and_undirected_weighted_graph.py b/graphs/directed_and_undirected_weighted_graph.py index 8ca645fdace8..5dbef485a091 100644 --- a/graphs/directed_and_undirected_weighted_graph.py +++ b/graphs/directed_and_undirected_weighted_graph.py @@ -7,7 +7,7 @@ class DirectedGraph: - def __init__(self): + def __init__(self) -> None: self.graph = {} # adding vertices and edges @@ -262,7 +262,7 @@ def bfs_time(self, s=-2): class Graph: - def __init__(self): + def __init__(self) -> None: self.graph = {} # adding vertices and edges diff --git a/graphs/edmonds_karp_multiple_source_and_sink.py b/graphs/edmonds_karp_multiple_source_and_sink.py index 5c774f4b812b..34a66760bff7 100644 --- a/graphs/edmonds_karp_multiple_source_and_sink.py +++ b/graphs/edmonds_karp_multiple_source_and_sink.py @@ -1,5 +1,5 @@ class FlowNetwork: - def __init__(self, graph, sources, sinks): + def __init__(self, graph, sources, sinks) -> None: self.source_index = None self.sink_index = None self.graph = graph @@ -58,7 +58,7 @@ def set_maximum_flow_algorithm(self, algorithm): class FlowNetworkAlgorithmExecutor: - def __init__(self, flow_network): + def __init__(self, flow_network) -> None: self.flow_network = flow_network self.verticies_count = flow_network.verticesCount self.source_index = flow_network.sourceIndex @@ -79,7 +79,7 @@ def _algorithm(self): class MaximumFlowAlgorithmExecutor(FlowNetworkAlgorithmExecutor): - def __init__(self, flow_network): + def __init__(self, flow_network) -> None: super().__init__(flow_network) # use this to save your result self.maximum_flow = -1 @@ -92,7 +92,7 @@ def get_maximum_flow(self): class PushRelabelExecutor(MaximumFlowAlgorithmExecutor): - def __init__(self, flow_network): + def __init__(self, flow_network) -> None: super().__init__(flow_network) self.preflow = [[0] * self.verticies_count for i in range(self.verticies_count)] diff --git a/graphs/greedy_best_first.py b/graphs/greedy_best_first.py index bb3160047e34..4da8631328bd 100644 --- a/graphs/greedy_best_first.py +++ b/graphs/greedy_best_first.py @@ -61,7 +61,7 @@ def __init__( goal_y: int, g_cost: float, parent: Node | None, - ): + ) -> None: self.pos_x = pos_x self.pos_y = pos_y self.pos = (pos_y, pos_x) @@ -106,7 +106,7 @@ class GreedyBestFirst: def __init__( self, grid: list[list[int]], start: tuple[int, int], goal: tuple[int, int] - ): + ) -> None: self.grid = grid self.start = Node(start[1], start[0], goal[1], goal[0], 0, None) self.target = Node(goal[1], goal[0], goal[1], goal[0], 99999, None) diff --git a/graphs/markov_chain.py b/graphs/markov_chain.py index 0b6659822dc4..1028522f7161 100644 --- a/graphs/markov_chain.py +++ b/graphs/markov_chain.py @@ -9,7 +9,7 @@ class MarkovChainGraphUndirectedUnweighted: Undirected Unweighted Graph for running Markov Chain Algorithm """ - def __init__(self): + def __init__(self) -> None: self.connections = {} def add_node(self, node: str) -> None: diff --git a/graphs/minimum_spanning_tree_boruvka.py b/graphs/minimum_spanning_tree_boruvka.py index f234d65ab765..d8aaaf37eb3d 100644 --- a/graphs/minimum_spanning_tree_boruvka.py +++ b/graphs/minimum_spanning_tree_boruvka.py @@ -3,7 +3,7 @@ class Graph: Data structure to store graphs (based on adjacency lists) """ - def __init__(self): + def __init__(self) -> None: self.num_vertices = 0 self.num_edges = 0 self.adjacency = {} @@ -54,7 +54,7 @@ def distinct_weight(self): self.adjacency[head][tail] = weight self.adjacency[tail][head] = weight - def __str__(self): + def __str__(self) -> str: """ Returns string representation of the graph """ @@ -103,11 +103,11 @@ class UnionFind: Disjoint set Union and Find for Boruvka's algorithm """ - def __init__(self): + def __init__(self) -> None: self.parent = {} self.rank = {} - def __len__(self): + def __len__(self) -> int: return len(self.parent) def make_set(self, item): diff --git a/graphs/minimum_spanning_tree_prims.py b/graphs/minimum_spanning_tree_prims.py index d0b45d7ef139..4765d71cd068 100644 --- a/graphs/minimum_spanning_tree_prims.py +++ b/graphs/minimum_spanning_tree_prims.py @@ -3,7 +3,7 @@ class Heap: - def __init__(self): + def __init__(self) -> None: self.node_position = [] def get_position(self, vertex): diff --git a/graphs/multi_heuristic_astar.py b/graphs/multi_heuristic_astar.py index 38b07e1ca675..fbc5ebddfbb0 100644 --- a/graphs/multi_heuristic_astar.py +++ b/graphs/multi_heuristic_astar.py @@ -7,7 +7,7 @@ class PriorityQueue: - def __init__(self): + def __init__(self) -> None: self.elements = [] self.set = set() diff --git a/graphs/page_rank.py b/graphs/page_rank.py index 56274bddcbb7..8e0cbb53094a 100644 --- a/graphs/page_rank.py +++ b/graphs/page_rank.py @@ -16,7 +16,7 @@ class Node: - def __init__(self, name): + def __init__(self, name) -> None: self.name = name self.inbound = [] self.outbound = [] @@ -27,7 +27,7 @@ def add_inbound(self, node): def add_outbound(self, node): self.outbound.append(node) - def __repr__(self): + def __repr__(self) -> str: return f"" diff --git a/graphs/prim.py b/graphs/prim.py index 5b3ce04441ec..50ce40de63c1 100644 --- a/graphs/prim.py +++ b/graphs/prim.py @@ -13,7 +13,7 @@ class Vertex: """Class Vertex.""" - def __init__(self, id_): + def __init__(self, id_) -> None: """ Arguments: id - input an id to identify the vertex @@ -31,7 +31,7 @@ def __lt__(self, other): """Comparison rule to < operator.""" return self.key < other.key - def __repr__(self): + def __repr__(self) -> str: """Return the vertex id.""" return self.id diff --git a/hashes/sha1.py b/hashes/sha1.py index 75a1423e9b5f..1c6dadf95784 100644 --- a/hashes/sha1.py +++ b/hashes/sha1.py @@ -38,7 +38,7 @@ class SHA1Hash: '872af2d8ac3d8695387e7c804bf0e02c18df9e6e' """ - def __init__(self, data): + def __init__(self, data) -> None: """ Initiates the variables data and h. h is a list of 5 8-digit hexadecimal numbers corresponding to diff --git a/machine_learning/astar.py b/machine_learning/astar.py index a5859e51fe70..8bd74f4ec539 100644 --- a/machine_learning/astar.py +++ b/machine_learning/astar.py @@ -24,7 +24,7 @@ class Cell: g, h, f: Parameters used when calling our heuristic function. """ - def __init__(self): + def __init__(self) -> None: self.position = (0, 0) self.parent = None self.g = 0 @@ -50,7 +50,7 @@ class Gridworld: world_size: create a numpy array with the given world_size default is 5. """ - def __init__(self, world_size=(5, 5)): + def __init__(self, world_size=(5, 5)) -> None: self.w = np.zeros(world_size) self.world_x_limit = world_size[0] self.world_y_limit = world_size[1] diff --git a/machine_learning/decision_tree.py b/machine_learning/decision_tree.py index b4df64796bb1..653870edcb25 100644 --- a/machine_learning/decision_tree.py +++ b/machine_learning/decision_tree.py @@ -8,7 +8,7 @@ class DecisionTree: - def __init__(self, depth=5, min_leaf_size=5): + def __init__(self, depth=5, min_leaf_size=5) -> None: self.depth = depth self.decision_boundary = 0 self.left = None diff --git a/machine_learning/sequential_minimum_optimization.py b/machine_learning/sequential_minimum_optimization.py index e96f06d6f080..f2f6b6764d5f 100644 --- a/machine_learning/sequential_minimum_optimization.py +++ b/machine_learning/sequential_minimum_optimization.py @@ -54,7 +54,7 @@ def __init__( b=0.0, tolerance=0.001, auto_norm=True, - ): + ) -> None: self._init = True self._auto_norm = auto_norm self._c = np.float64(cost) @@ -402,7 +402,7 @@ def length(self): class Kernel: - def __init__(self, kernel, degree=1.0, coef0=0.0, gamma=1.0): + def __init__(self, kernel, degree=1.0, coef0=0.0, gamma=1.0) -> None: self.degree = np.float64(degree) self.coef0 = np.float64(coef0) self.gamma = np.float64(gamma) @@ -430,7 +430,7 @@ def _get_kernel(self, kernel_name): def __call__(self, v1, v2): return self._kernel(v1, v2) - def __repr__(self): + def __repr__(self) -> str: return self._kernel_name diff --git a/maths/dual_number_automatic_differentiation.py b/maths/dual_number_automatic_differentiation.py index 09aeb17a4aea..c4841a0924b2 100644 --- a/maths/dual_number_automatic_differentiation.py +++ b/maths/dual_number_automatic_differentiation.py @@ -9,14 +9,14 @@ class Dual: - def __init__(self, real, rank): + def __init__(self, real, rank) -> None: self.real = real if isinstance(rank, int): self.duals = [1] * rank else: self.duals = rank - def __repr__(self): + def __repr__(self) -> str: s = "+".join(f"{dual}E{n}" for n, dual in enumerate(self.duals, 1)) return f"{self.real}+{s}" diff --git a/maths/monte_carlo_dice.py b/maths/monte_carlo_dice.py index 362f70b49828..ffe693a84910 100644 --- a/maths/monte_carlo_dice.py +++ b/maths/monte_carlo_dice.py @@ -6,7 +6,7 @@ class Dice: NUM_SIDES = 6 - def __init__(self): + def __init__(self) -> None: """Initialize a six sided dice""" self.sides = list(range(1, Dice.NUM_SIDES + 1)) diff --git a/maths/pythagoras.py b/maths/pythagoras.py index 7770e981d44d..bb236c05281f 100644 --- a/maths/pythagoras.py +++ b/maths/pythagoras.py @@ -4,7 +4,7 @@ class Point: - def __init__(self, x, y, z): + def __init__(self, x, y, z) -> None: self.x = x self.y = y self.z = z diff --git a/maths/radix2_fft.py b/maths/radix2_fft.py index 5efbccc7a17d..579a1233455c 100644 --- a/maths/radix2_fft.py +++ b/maths/radix2_fft.py @@ -49,7 +49,7 @@ class FFT: A*B = (-0-0j)*x^0 + (2+0j)*x^1 + (3-0j)*x^2 + (8-0j)*x^3 + (6+0j)*x^4 + (8+0j)*x^5 """ - def __init__(self, poly_a=None, poly_b=None): + def __init__(self, poly_a=None, poly_b=None) -> None: # Input as list self.polyA = list(poly_a or [0])[:] self.polyB = list(poly_b or [0])[:] @@ -157,7 +157,7 @@ def __multiply(self): return inverce_c # Overwrite __str__ for print(); Shows A, B and A*B - def __str__(self): + def __str__(self) -> str: a = "A = " + " + ".join( f"{coef}*x^{i}" for i, coef in enumerate(self.polyA[: self.len_A]) ) diff --git a/matrix/matrix_class.py b/matrix/matrix_class.py index dee9247282f9..bdafc5eae3bb 100644 --- a/matrix/matrix_class.py +++ b/matrix/matrix_class.py @@ -107,7 +107,7 @@ class Matrix: [414. 513. 612. 640.]] """ - def __init__(self, rows: list[list[int]]): + def __init__(self, rows: list[list[int]]) -> None: error = TypeError( "Matrices must be formed from a list of zero or more lists containing at " "least one and the same number of values, each of which must be of type " diff --git a/neural_network/back_propagation_neural_network.py b/neural_network/back_propagation_neural_network.py index 182f759c5fc7..8bd5073aad70 100644 --- a/neural_network/back_propagation_neural_network.py +++ b/neural_network/back_propagation_neural_network.py @@ -33,7 +33,7 @@ class DenseLayer: def __init__( self, units, activation=None, learning_rate=None, is_input_layer=False - ): + ) -> None: """ common connected layer of bp network :param units: numbers of neural units @@ -101,7 +101,7 @@ class BPNN: Back Propagation Neural Network model """ - def __init__(self): + def __init__(self) -> None: self.layers = [] self.train_mse = [] self.fig_loss = plt.figure() diff --git a/neural_network/convolution_neural_network.py b/neural_network/convolution_neural_network.py index 6b1aa50c7981..f9f8d16fb29f 100644 --- a/neural_network/convolution_neural_network.py +++ b/neural_network/convolution_neural_network.py @@ -23,7 +23,7 @@ class CNN: def __init__( self, conv1_get, size_p1, bp_num1, bp_num2, bp_num3, rate_w=0.2, rate_t=0.2 - ): + ) -> None: """ :param conv1_get: [a,c,d], size, number, step of convolution kernel :param size_p1: pooling size diff --git a/neural_network/input_data.py b/neural_network/input_data.py index 7f0b7538df54..a8260f3ff8a1 100644 --- a/neural_network/input_data.py +++ b/neural_network/input_data.py @@ -132,7 +132,7 @@ def __init__( dtype=dtypes.float32, reshape=True, seed=None, - ): + ) -> None: """Construct a _DataSet. one_hot arg is used only if fake_data is true. `dtype` can be either diff --git a/other/graham_scan.py b/other/graham_scan.py index 3f11d40f141c..d4e349a9e67c 100644 --- a/other/graham_scan.py +++ b/other/graham_scan.py @@ -21,7 +21,7 @@ class Direction(Enum): straight = 2 right = 3 - def __repr__(self): + def __repr__(self) -> str: return f"{self.__class__.__name__}.{self.name}" diff --git a/other/greedy.py b/other/greedy.py index 72e05f451fbb..a1f10b84457a 100644 --- a/other/greedy.py +++ b/other/greedy.py @@ -1,10 +1,10 @@ class Things: - def __init__(self, name, value, weight): + def __init__(self, name, value, weight) -> None: self.name = name self.value = value self.weight = weight - def __repr__(self): + def __repr__(self) -> str: return f"{self.__class__.__name__}({self.name}, {self.value}, {self.weight})" def get_value(self): diff --git a/other/lfu_cache.py b/other/lfu_cache.py index 6eaacff2966a..3ba5632652d2 100644 --- a/other/lfu_cache.py +++ b/other/lfu_cache.py @@ -16,7 +16,7 @@ class DoubleLinkedListNode[T, U]: Node: key: 1, val: 1, freq: 0, has next: False, has prev: False """ - def __init__(self, key: T | None, val: U | None): + def __init__(self, key: T | None, val: U | None) -> None: self.key = key self.val = val self.freq: int = 0 @@ -196,7 +196,7 @@ class LFUCache[T, U]: CacheInfo(hits=196, misses=100, capacity=100, current_size=100) """ - def __init__(self, capacity: int): + def __init__(self, capacity: int) -> None: self.list: DoubleLinkedList[T, U] = DoubleLinkedList() self.capacity = capacity self.num_keys = 0 diff --git a/other/linear_congruential_generator.py b/other/linear_congruential_generator.py index c7de15b94bbd..00c2b404e710 100644 --- a/other/linear_congruential_generator.py +++ b/other/linear_congruential_generator.py @@ -14,7 +14,7 @@ class LinearCongruentialGenerator: # called once per instance and it ensures that each instance will generate a unique # sequence of numbers. - def __init__(self, multiplier, increment, modulo, seed=int(time())): # noqa: B008 + def __init__(self, multiplier, increment, modulo, seed=int(time())) -> None: # noqa: B008 """ These parameters are saved and used when nextNumber() is called. diff --git a/other/lru_cache.py b/other/lru_cache.py index 058b03b021bc..f2c3a0fa1b52 100644 --- a/other/lru_cache.py +++ b/other/lru_cache.py @@ -15,7 +15,7 @@ class DoubleLinkedListNode[T, U]: Node: key: 1, val: 1, has next: False, has prev: False """ - def __init__(self, key: T | None, val: U | None): + def __init__(self, key: T | None, val: U | None) -> None: self.key = key self.val = val self.next: DoubleLinkedListNode[T, U] | None = None @@ -209,7 +209,7 @@ class LRUCache[T, U]: CacheInfo(hits=194, misses=99, capacity=100, current size=99) """ - def __init__(self, capacity: int): + def __init__(self, capacity: int) -> None: self.list: DoubleLinkedList[T, U] = DoubleLinkedList() self.capacity = capacity self.num_keys = 0 diff --git a/project_euler/problem_054/sol1.py b/project_euler/problem_054/sol1.py index 66aa3a0826f5..d0c023f04566 100644 --- a/project_euler/problem_054/sol1.py +++ b/project_euler/problem_054/sol1.py @@ -324,10 +324,10 @@ def _internal_state(self) -> tuple[list[int], set[str]]: card_suit = {card[-1] for card in new_hand} return sorted(card_values, reverse=True), card_suit - def __repr__(self): + def __repr__(self) -> str: return f'{self.__class__}("{self._hand}")' - def __str__(self): + def __str__(self) -> str: return self._hand # Rich comparison operators (used in list.sort() and sorted() builtin functions) diff --git a/searches/binary_tree_traversal.py b/searches/binary_tree_traversal.py index 0886e599f822..66185a0c25b4 100644 --- a/searches/binary_tree_traversal.py +++ b/searches/binary_tree_traversal.py @@ -8,7 +8,7 @@ class TreeNode: - def __init__(self, data): + def __init__(self, data) -> None: self.data = data self.right = None self.left = None diff --git a/sorts/external_sort.py b/sorts/external_sort.py index cfddee4fe7f8..5e0b112f0fe8 100644 --- a/sorts/external_sort.py +++ b/sorts/external_sort.py @@ -10,7 +10,7 @@ class FileSplitter: BLOCK_FILENAME_FORMAT = "block_{0}.dat" - def __init__(self, filename): + def __init__(self, filename) -> None: self.filename = filename self.block_filenames = [] @@ -57,7 +57,7 @@ def select(self, choices): class FilesArray: - def __init__(self, files): + def __init__(self, files) -> None: self.files = files self.empty = set() self.num_buffers = len(files) @@ -87,7 +87,7 @@ def unshift(self, index): class FileMerger: - def __init__(self, merge_strategy): + def __init__(self, merge_strategy) -> None: self.merge_strategy = merge_strategy def merge(self, filenames, outfilename, buffer_size): @@ -107,7 +107,7 @@ def get_file_handles(self, filenames, buffer_size): class ExternalSort: - def __init__(self, block_size): + def __init__(self, block_size) -> None: self.block_size = block_size def sort(self, filename, sort_key=None): diff --git a/strings/aho_corasick.py b/strings/aho_corasick.py index e32a4ba64fac..5d0973ff1bd2 100644 --- a/strings/aho_corasick.py +++ b/strings/aho_corasick.py @@ -4,7 +4,7 @@ class Automaton: - def __init__(self, keywords: list[str]): + def __init__(self, keywords: list[str]) -> None: self.adlist: list[dict] = [] self.adlist.append( {"value": "", "next_states": [], "fail_state": 0, "output": []} diff --git a/strings/boyer_moore_search.py b/strings/boyer_moore_search.py index 3783c4bfe35c..74c11835faae 100644 --- a/strings/boyer_moore_search.py +++ b/strings/boyer_moore_search.py @@ -32,7 +32,7 @@ class BoyerMooreSearch: where 'positions' contain the locations where the pattern was matched. """ - def __init__(self, text: str, pattern: str): + def __init__(self, text: str, pattern: str) -> None: self.text, self.pattern = text, pattern self.textLen, self.patLen = len(text), len(pattern) diff --git a/web_programming/instagram_crawler.py b/web_programming/instagram_crawler.py index 2d267c937522..3dced42d1442 100644 --- a/web_programming/instagram_crawler.py +++ b/web_programming/instagram_crawler.py @@ -41,7 +41,7 @@ class InstagramUser: 'Built for developers.' """ - def __init__(self, username): + def __init__(self, username) -> None: self.url = f"https://www.instagram.com/{username}/" self.user_data = self.get_json()