MCPcopy Index your code
hub / github.com/pydata/xarray / _check_loop

Method _check_loop

xarray/core/treenode.py:113–124  ·  view source on GitHub ↗

Checks that assignment of this new parent will not create a cycle.

(self, new_parent: Self | None)

Source from the content-addressed store, hash-verified

111 self._attach(new_parent, child_name)
112
113 def _check_loop(self, new_parent: Self | None) -> None:
114 """Checks that assignment of this new parent will not create a cycle."""
115 if new_parent is not None:
116 if new_parent is self:
117 raise InvalidTreeError(
118 f"Cannot set parent, as node {self} cannot be a parent of itself."
119 )
120
121 if self._is_descendant_of(new_parent):
122 raise InvalidTreeError(
123 "Cannot set parent, as intended parent is already a descendant of this node."
124 )
125
126 def _is_descendant_of(self, node: Self) -> bool:
127 return any(n is self for n in node.parents)

Callers 1

_set_parentMethod · 0.95

Calls 2

_is_descendant_ofMethod · 0.95
InvalidTreeErrorClass · 0.85

Tested by

no test coverage detected