Skip to content

Commit

Permalink
Added type annotations and errors types refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
Raalsky committed May 26, 2020
1 parent f214ebf commit 1d298ea
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions core/dbt/graph/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,20 +338,20 @@ def select_childrens_parents(self, selected: Set[str]) -> Set[str]:
ancestors_for = self.select_children(selected) | selected
return self.select_parents(ancestors_for) | ancestors_for

def descendants(self, node, max_depth: int = None):
def descendants(self, node, max_depth: Optional[int] = None) -> Set[str]:
"""Returns all nodes reachable from `node` in `graph`"""
if not self.graph.has_node(node):
raise nx.NetworkXError(f"The node {node} is not in the graph.")
raise InternalException(f'Node {node} not found in the graph!')
des = nx.single_source_shortest_path_length(G=self.graph,
source=node,
cutoff=max_depth)\
.keys()
return des - {node}

def ancestors(self, node, max_depth: int = None):
def ancestors(self, node, max_depth: Optional[int] = None) -> Set[str]:
"""Returns all nodes having a path to `node` in `graph`"""
if not self.graph.has_node(node):
raise nx.NetworkXError(f"The node {node} is not in the graph.")
raise InternalException(f'Node {node} not found in the graph!')
with nx.utils.reversed(self.graph):
anc = nx.single_source_shortest_path_length(G=self.graph,
source=node,
Expand All @@ -361,15 +361,15 @@ def ancestors(self, node, max_depth: int = None):

def select_children(self,
selected: Set[str],
max_depth: int = None) -> Set[str]:
max_depth: Optional[int] = None) -> Set[str]:
descendants: Set[str] = set()
for node in selected:
descendants.update(self.descendants(node, max_depth=max_depth))
return descendants

def select_parents(self,
selected: Set[str],
max_depth: int = None) -> Set[str]:
max_depth: Optional[int] = None) -> Set[str]:
ancestors: Set[str] = set()
for node in selected:
ancestors.update(self.ancestors(node, max_depth=max_depth))
Expand Down

0 comments on commit 1d298ea

Please sign in to comment.