Set the point at which create_node and companion methods will insert into the graph. When used within a 'with' statement, this will temporary set the insert point and then restore it when the with statement exits:: with g.inserting_after(n): ... # inserti
(self, n: Optional[Node] = None)
| 977 | |
| 978 | @compatibility(is_backward_compatible=True) |
| 979 | def inserting_after(self, n: Optional[Node] = None): |
| 980 | """Set the point at which create_node and companion methods will insert into the graph. |
| 981 | When used within a 'with' statement, this will temporary set the insert point and |
| 982 | then restore it when the with statement exits:: |
| 983 | |
| 984 | with g.inserting_after(n): |
| 985 | ... # inserting after node n |
| 986 | ... # insert point restored to what it was previously |
| 987 | g.inserting_after(n) # set the insert point permanently |
| 988 | |
| 989 | Args: |
| 990 | |
| 991 | n (Optional[Node]): The node before which to insert. If None this will insert after |
| 992 | the beginning of the entire graph. |
| 993 | |
| 994 | Returns: |
| 995 | A resource manager that will restore the insert point on ``__exit__``. |
| 996 | """ |
| 997 | if n is None: |
| 998 | return self.inserting_before(self._root) |
| 999 | assert n.graph == self, "Node to insert after is not in graph." |
| 1000 | return _InsertPoint(self, n.append) |
| 1001 | |
| 1002 | @compatibility(is_backward_compatible=True) |
| 1003 | def placeholder(self, name: str, type_expr: Optional[Any] = None, |