2121if TYPE_CHECKING :
2222 from collections .abc import Sequence
2323
24- from networkx .classes .reportviews import DegreeView
25-
2624 from .versioning .rundescribertypes import InterDependencies_Dict
2725_LOGGER = logging .getLogger (__name__ )
2826ParamSpecTree = dict [ParamSpecBase , tuple [ParamSpecBase , ...]]
@@ -137,9 +135,6 @@ def _validate_acyclic(self, interdeps: ParamSpecTree) -> None:
137135 def _validate_no_chained_dependencies (self , interdeps : ParamSpecTree ) -> None :
138136 for node , in_degree in self ._dependency_subgraph .in_degree :
139137 out_degree = self ._dependency_subgraph .out_degree (node )
140- assert isinstance (out_degree , int ), (
141- "The out_degree method with arguments should have returned an int"
142- )
143138 if in_degree > 0 and out_degree > 0 :
144139 depends_on_nodes = list (self ._dependency_subgraph .successors (node ))
145140 depended_on_nodes = list (self ._dependency_subgraph .predecessors (node ))
@@ -155,6 +150,8 @@ def _dependency_subgraph(self) -> nx.DiGraph[str]:
155150 for edge in self .graph .edges
156151 if self .graph .edges [edge ]["interdep_type" ] == "depends_on"
157152 ]
153+ # the type annotations does not currently encode that edge_subgraph of a DiGraph
154+ # is a DiGraph
158155 return cast ("nx.DiGraph[str]" , self .graph .edge_subgraph (depends_on_edges ))
159156
160157 @property
@@ -164,6 +161,8 @@ def _inference_subgraph(self) -> nx.DiGraph[str]:
164161 for edge in self .graph .edges
165162 if self .graph .edges [edge ]["interdep_type" ] == "inferred_from"
166163 ]
164+ # the type annotations does not currently encode that edge_subgraph of a DiGraph
165+ # is a DiGraph
167166 return cast ("nx.DiGraph[str]" , self .graph .edge_subgraph (inferred_from_edges ))
168167
169168 def extend (
@@ -195,7 +194,7 @@ def _paramspec_tree_by_type(self, interdep_type: _InterDepType) -> ParamSpecTree
195194 return {key : tuple (val ) for key , val in paramspec_tree_list .items ()}
196195
197196 def _node_to_paramspec (self , node_id : str ) -> ParamSpecBase :
198- return cast ( "ParamSpecBase" , self .graph .nodes [node_id ]["value" ])
197+ return self .graph .nodes [node_id ]["value" ]
199198
200199 def _paramspec_predecessors_by_type (
201200 self , paramspec : ParamSpecBase , interdep_type : _InterDepType
@@ -247,13 +246,10 @@ def inferences(self) -> ParamSpecTree:
247246
248247 @property
249248 def standalones (self ) -> frozenset [ParamSpecBase ]:
250- # since we are not requesting the degree of a specific node, we will get a DegreeView
251- # the type stubs does not yet reflect this so we cast away the int type here
252- degree_iterator = cast ("DegreeView[str]" , self .graph .degree )
253249 return frozenset (
254250 [
255251 self ._node_to_paramspec (node_id )
256- for node_id , degree in degree_iterator
252+ for node_id , degree in self . graph . degree
257253 if degree == 0
258254 ]
259255 )
@@ -270,10 +266,7 @@ def paramspecs(self) -> tuple[ParamSpecBase, ...]:
270266 """
271267 Return the ParamSpecBase objects of this instance
272268 """
273- return tuple (
274- cast ("ParamSpecBase" , paramspec )
275- for _ , paramspec in self .graph .nodes (data = "value" )
276- )
269+ return tuple (paramspec for _ , paramspec in self .graph .nodes (data = "value" ))
277270
278271 @property
279272 @deprecated (
@@ -319,9 +312,7 @@ def top_level_parameters(self) -> tuple[ParamSpecBase, ...]:
319312 }
320313 standalone_top_level = {
321314 self ._node_to_paramspec (node_id )
322- # since we are not requesting the degree of a specific node, we will get a DegreeView
323- # the type stubs does not yet reflect this so we cast away the int type here
324- for node_id , degree in cast ("DegreeView[str]" , self ._graph .degree )
315+ for node_id , degree in self ._graph .degree
325316 if degree == 0
326317 }
327318
@@ -349,9 +340,6 @@ def remove(self, paramspec: ParamSpecBase) -> InterDependencies_:
349340 to this instance, but has the given parameter removed.
350341 """
351342 paramspec_in_degree = self .graph .in_degree (paramspec .name )
352- assert isinstance (paramspec_in_degree , int ), (
353- "The in_degree method with arguments should have returned an int"
354- )
355343 if paramspec_in_degree > 0 :
356344 raise ValueError (
357345 f"Cannot remove { paramspec .name } , other parameters depend on or are inferred from it"
0 commit comments