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]
)
| 380 | return kwargs.get(self.name, default) |
| 381 | |
| 382 | def replace( |
| 383 | self, new_value: Any, args: Sequence[Any], kwargs: Dict[str, Any] |
| 384 | ) -> Tuple[Any, Sequence[Any], Dict[str, Any]]: |
| 385 | """Replace the named argument in ``args, kwargs`` with ``new_value``. |
| 386 | |
| 387 | Returns ``(old_value, args, kwargs)``. The returned ``args`` and |
| 388 | ``kwargs`` objects may not be the same as the input objects, or |
| 389 | the input objects may be mutated. |
| 390 | |
| 391 | If the named argument was not found, ``new_value`` will be added |
| 392 | to ``kwargs`` and None will be returned as ``old_value``. |
| 393 | """ |
| 394 | if self.arg_pos is not None and len(args) > self.arg_pos: |
| 395 | # The arg to replace is passed positionally |
| 396 | old_value = args[self.arg_pos] |
| 397 | args = list(args) # *args is normally a tuple |
| 398 | args[self.arg_pos] = new_value |
| 399 | else: |
| 400 | # The arg to replace is either omitted or passed by keyword. |
| 401 | old_value = kwargs.get(self.name) |
| 402 | kwargs[self.name] = new_value |
| 403 | return old_value, args, kwargs |
| 404 | |
| 405 | |
| 406 | def timedelta_to_seconds(td): |