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]
)
| 407 | return kwargs.get(self.name, default) |
| 408 | |
| 409 | def replace( |
| 410 | self, new_value: Any, args: Sequence[Any], kwargs: Dict[str, Any] |
| 411 | ) -> Tuple[Any, Sequence[Any], Dict[str, Any]]: |
| 412 | """Replace the named argument in ``args, kwargs`` with ``new_value``. |
| 413 | |
| 414 | Returns ``(old_value, args, kwargs)``. The returned ``args`` and |
| 415 | ``kwargs`` objects may not be the same as the input objects, or |
| 416 | the input objects may be mutated. |
| 417 | |
| 418 | If the named argument was not found, ``new_value`` will be added |
| 419 | to ``kwargs`` and None will be returned as ``old_value``. |
| 420 | """ |
| 421 | if self.arg_pos is not None and len(args) > self.arg_pos: |
| 422 | # The arg to replace is passed positionally |
| 423 | old_value = args[self.arg_pos] |
| 424 | args = list(args) # *args is normally a tuple |
| 425 | args[self.arg_pos] = new_value |
| 426 | else: |
| 427 | # The arg to replace is either omitted or passed by keyword. |
| 428 | old_value = kwargs.get(self.name) |
| 429 | kwargs[self.name] = new_value |
| 430 | return old_value, args, kwargs |
| 431 | |
| 432 | |
| 433 | def timedelta_to_seconds(td): |