Skip to content

Commit 45e52ba

Browse files
committed
add type hints
1 parent 189581a commit 45e52ba

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

manim/mobject/graph.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from .geometry import Dot, Line, LabeledDot
1111
from .svg.tex_mobject import MathTex
1212

13+
from typing import Hashable, Union, List, Tuple
14+
1315
from copy import copy
1416
import networkx as nx
1517
import numpy as np
@@ -144,18 +146,18 @@ def construct(self):
144146

145147
def __init__(
146148
self,
147-
vertices,
148-
edges,
149-
labels=False,
150-
label_fill_color=BLACK,
151-
layout="spring",
152-
layout_scale=2,
153-
layout_config=None,
154-
vertex_type=Dot,
155-
vertex_config=None,
156-
edge_type=Line,
157-
edge_config=None,
158-
):
149+
vertices: List[Hashable],
150+
edges: List[Tuple[Hashable, Hashable]],
151+
labels: bool = False,
152+
label_fill_color: str = BLACK,
153+
layout: Union[str, dict] = "spring",
154+
layout_scale: float = 2,
155+
layout_config: Union[dict, None] = None,
156+
vertex_type: "Mobject" = Dot,
157+
vertex_config: Union[dict, None] = None,
158+
edge_type: "Mobject" = Line,
159+
edge_config: Union[dict, None] = None,
160+
) -> None:
159161
VMobject.__init__(self)
160162

161163
nx_graph = nx.Graph()
@@ -274,8 +276,8 @@ def update_edge(e, u=u, v=v):
274276
update_edge(edge)
275277
edge.add_updater(update_edge)
276278

277-
def __getitem__(self, v):
279+
def __getitem__(self: "Graph", v: Hashable) -> "Mobject":
278280
return self.vertices[v]
279281

280-
def __repr__(self):
282+
def __repr__(self: "Graph") -> str:
281283
return f"Graph on {len(self.vertices)} vertices and {len(self.edges)} edges"

0 commit comments

Comments
 (0)