Insert an positional argument to the argument list with given index. Args: idx (int): The index of the element in ``self.args`` to be inserted before. arg (Argument): The new argument value to insert into ``args``
(self, idx : int, arg : Argument)
| 368 | |
| 369 | @compatibility(is_backward_compatible=True) |
| 370 | def insert_arg(self, idx : int, arg : Argument) -> None: |
| 371 | """ |
| 372 | Insert an positional argument to the argument list with given index. |
| 373 | |
| 374 | Args: |
| 375 | |
| 376 | idx (int): The index of the element in ``self.args`` to be inserted before. |
| 377 | arg (Argument): The new argument value to insert into ``args`` |
| 378 | """ |
| 379 | assert 0 <= idx <= len(self.args), "insert_args index must be between 0 and len(self.args)" |
| 380 | args_left = self.args[:idx] |
| 381 | args_right = self.args[idx:] |
| 382 | |
| 383 | self._args = args_left + (arg,) + args_right |
| 384 | |
| 385 | _new_input_nodes = {} |
| 386 | map_arg(arg, _new_input_nodes.setdefault) |
| 387 | |
| 388 | for new_use in _new_input_nodes.keys(): |
| 389 | if new_use not in self._input_nodes: |
| 390 | self._input_nodes.setdefault(new_use) |
| 391 | new_use.users.setdefault(self) |
| 392 | |
| 393 | @compatibility(is_backward_compatible=True) |
| 394 | def update_kwarg(self, key : str, arg : Argument) -> None: |