Skip to content

Commit 3dae007

Browse files
authored
More ruff rules ANN for type annotations (#15443)
1 parent f59bddb commit 3dae007

17 files changed

Lines changed: 174 additions & 40 deletions

File tree

‎data_structures/binary_tree/serialize_deserialize_binary_tree.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TreeNode:
1919
left: TreeNode | None = None
2020
right: TreeNode | None = None
2121

22-
def __post_init__(self):
22+
def __post_init__(self) -> None:
2323
if not isinstance(self.value, int):
2424
raise TypeError("Value must be an integer.")
2525

‎data_structures/heap/min_heap.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def __init__(self, name, val) -> None:
1010
def __str__(self) -> str:
1111
return f"{self.__class__.__name__}({self.name}, {self.val})"
1212

13-
def __lt__(self, other):
13+
def __lt__(self, other) -> bool:
1414
return self.val < other.val
1515

1616

‎data_structures/linked_list/has_loop.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from collections.abc import Iterator
34
from typing import Any
45

56

@@ -12,7 +13,7 @@ def __init__(self, data: Any) -> None:
1213
self.data: Any = data
1314
self.next_node: Node | None = None
1415

15-
def __iter__(self):
16+
def __iter__(self) -> Iterator[Any]:
1617
node = self
1718
visited = set()
1819
while node:

‎divide_and_conquer/convex_hull.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,30 @@ class Point:
4848
def __init__(self, x, y) -> None:
4949
self.x, self.y = float(x), float(y)
5050

51-
def __eq__(self, other):
51+
def __eq__(self, other) -> bool:
5252
return self.x == other.x and self.y == other.y
5353

54-
def __ne__(self, other):
54+
def __ne__(self, other) -> bool:
5555
return not self == other
5656

57-
def __gt__(self, other):
57+
def __gt__(self, other) -> bool:
5858
if self.x > other.x:
5959
return True
6060
elif self.x == other.x:
6161
return self.y > other.y
6262
return False
6363

64-
def __lt__(self, other):
64+
def __lt__(self, other) -> bool:
6565
return not self > other
6666

67-
def __ge__(self, other):
67+
def __ge__(self, other) -> bool:
6868
if self.x > other.x:
6969
return True
7070
elif self.x == other.x:
7171
return self.y >= other.y
7272
return False
7373

74-
def __le__(self, other):
74+
def __le__(self, other) -> bool:
7575
if self.x < other.x:
7676
return True
7777
elif self.x == other.x:
@@ -81,7 +81,7 @@ def __le__(self, other):
8181
def __repr__(self) -> str:
8282
return f"({self.x}, {self.y})"
8383

84-
def __hash__(self):
84+
def __hash__(self) -> int:
8585
return hash(self.x)
8686

8787

‎graphs/frequent_pattern_graph_miner.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
URL: https://www.researchgate.net/publication/235255851
1010
"""
11+
# ruff: noqa: Q000
1112

1213
# fmt: off
1314
edge_array = [

‎graphs/minimum_spanning_tree_boruvka.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def get_vertices(self):
8282
return self.adjacency.keys()
8383

8484
@staticmethod
85-
def build(vertices=None, edges=None):
85+
def build(vertices=None, edges=None) -> "Graph":
8686
"""
8787
Builds a graph from the given set of vertices and edges
8888
@@ -91,7 +91,7 @@ def build(vertices=None, edges=None):
9191
if vertices is None:
9292
vertices = []
9393
if edges is None:
94-
edge = []
94+
edges = []
9595
for vertex in vertices:
9696
g.add_vertex(vertex)
9797
for edge in edges:
@@ -147,7 +147,7 @@ def union(self, item1, item2):
147147
return None
148148

149149
@staticmethod
150-
def boruvka_mst(graph):
150+
def boruvka_mst(graph) -> "Graph":
151151
"""
152152
Implementation of Boruvka's algorithm
153153
>>> g = Graph()

‎graphs/prim.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self, id_) -> None:
2727
self.neighbors = []
2828
self.edges = {} # {vertex:distance}
2929

30-
def __lt__(self, other):
30+
def __lt__(self, other) -> bool:
3131
"""Comparison rule to < operator."""
3232
return self.key < other.key
3333

‎hashes/sha1.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self, data) -> None:
5050
self.h = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]
5151

5252
@staticmethod
53-
def rotate(n, b):
53+
def rotate(n, b) -> int:
5454
"""
5555
Static method to be used inside other methods. Left rotates n by b.
5656
>>> SHA1Hash('').rotate(12,2)

‎machine_learning/astar.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(self) -> None:
3636
wrong results.
3737
"""
3838

39-
def __eq__(self, cell):
39+
def __eq__(self, cell) -> bool:
4040
return self.position == cell.position
4141

4242
def showcell(self) -> None:

‎machine_learning/decision_tree.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class TestDecisionTree:
156156
"""Decision Tres test class"""
157157

158158
@staticmethod
159-
def helper_mean_squared_error_test(labels, prediction):
159+
def helper_mean_squared_error_test(labels, prediction) -> float:
160160
"""
161161
helper_mean_squared_error_test:
162162
@param labels: a one dimensional numpy array

0 commit comments

Comments
 (0)