Skip to content

Commit

Permalink
chore: check nx types
Browse files Browse the repository at this point in the history
  • Loading branch information
andylizf committed Nov 4, 2024
1 parent 24a9b99 commit 7798e23
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ types-requests<2.31
types-setuptools
types-cachetools
types-pyvmomi
types-networkx

# testing
pytest
Expand Down
9 changes: 4 additions & 5 deletions sky/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, name: Optional[str] = None) -> None:
"""
self.name = name
self._task_name_lookup: Dict[str, 'task.Task'] = {}
self.graph = nx.DiGraph()
self.graph: nx.DiGraph['task.Task'] = nx.DiGraph()

@property
def tasks(self) -> List['task.Task']:
Expand Down Expand Up @@ -213,7 +213,7 @@ def __exit__(self, exec_type: Any, exec_val: Any, exec_tb: Any) -> None:

def __repr__(self) -> str:
"""Return a string representation of the DAG."""
task_info = []
task_info: List[str] = []
for task in self.tasks:
downstream = self.get_downstream(task)
downstream_names = ','.join(
Expand All @@ -236,11 +236,10 @@ def is_chain(self) -> bool:
True if the DAG is a linear chain, False otherwise.
"""
nodes = list(self.graph.nodes)
out_degrees = [self.graph.out_degree(node) for node in nodes]

return (len(nodes) <= 1 or
(all(degree <= 1 for degree in out_degrees) and
sum(degree == 0 for degree in out_degrees) == 1))
(all(degree <= 1 for _, degree in self.graph.out_degree) and
sum(degree == 0 for _, degree in self.graph.out_degree) == 1))

def is_connected_dag(self) -> bool:
"""Check if the graph is a connected directed acyclic graph (DAG).
Expand Down

0 comments on commit 7798e23

Please sign in to comment.