Skip to content

Commit

Permalink
Fix default arguments are not respected when crafting cache key
Browse files Browse the repository at this point in the history
- Better error message on format key errors (mismatch of key parameters/provided arguments)
  • Loading branch information
Galtozzy committed Jan 8, 2025
1 parent 7e6b892 commit 572bb32
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions py_cachify/_backend/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@


def get_full_key_from_signature(bound_args: inspect.BoundArguments, key: str) -> str:
bound_args.apply_defaults()
args_dict = bound_args.arguments
args: Tuple[str, Any] = args_dict.pop('args', ())
args: Tuple[Any, ...] = args_dict.pop('args', ())
kwargs: Dict[str, Any] = args_dict.pop('kwargs', {})
kwargs.update(args_dict)

try:
return key.format(*args, **kwargs)
except IndexError:
raise ValueError('Arguments in a key do not match function signature') from None
except (IndexError, KeyError):
raise ValueError(f'Arguments in a key({key}) do not match function signature params({bound_args})') from None


def is_coroutine(
Expand Down

0 comments on commit 572bb32

Please sign in to comment.