Replace the named argument in ``args, kwargs`` with ``new_value``. Returns ``(old_value, args, kwargs)``. The returned ``args`` and ``kwargs`` objects may not be the same as the input objects, or the input objects may be mutated. If the named argument was not found
(
self, new_value: Any, args: Sequence[Any], kwargs: Dict[str, Any]
)
| 397 | return kwargs.get(self.name, default) |
| 398 | |
| 399 | def replace( |
| 400 | self, new_value: Any, args: Sequence[Any], kwargs: Dict[str, Any] |
| 401 | ) -> Tuple[Any, Sequence[Any], Dict[str, Any]]: |
| 402 | """Replace the named argument in ``args, kwargs`` with ``new_value``. |
| 403 | |
| 404 | Returns ``(old_value, args, kwargs)``. The returned ``args`` and |
| 405 | ``kwargs`` objects may not be the same as the input objects, or |
| 406 | the input objects may be mutated. |
| 407 | |
| 408 | If the named argument was not found, ``new_value`` will be added |
| 409 | to ``kwargs`` and None will be returned as ``old_value``. |
| 410 | """ |
| 411 | if self.arg_pos is not None and len(args) > self.arg_pos: |
| 412 | # The arg to replace is passed positionally |
| 413 | old_value = args[self.arg_pos] |
| 414 | args = list(args) # *args is normally a tuple |
| 415 | args[self.arg_pos] = new_value |
| 416 | else: |
| 417 | # The arg to replace is either omitted or passed by keyword. |
| 418 | old_value = kwargs.get(self.name) |
| 419 | kwargs[self.name] = new_value |
| 420 | return old_value, args, kwargs |
| 421 | |
| 422 | |
| 423 | def timedelta_to_seconds(td): |