Fix cache key generation for variadic arguments (*args, **kwargs)#322
Merged
Fix cache key generation for variadic arguments (*args, **kwargs)#322
Conversation
- Modified _convert_args_kwargs() to properly handle VAR_POSITIONAL and VAR_KEYWORD parameters - Variadic positional args are now expanded as individual entries with __varargs_N__ keys - Variadic keyword args are stored with their original keys - Added comprehensive test suite for variadic arguments - All existing tests pass including custom hash function tests Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix cachier to handle varadic arguments in cache key
Fix cache key generation for variadic arguments (*args, **kwargs)
Jan 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
✅ Fix for Variadic Arguments in Cache Key Generation - COMPLETE
Problem Solved
*argsdon't get unique cache keys_convert_args_kwargs()incore.pydoesn't properly handle VAR_POSITIONAL parameters_convert_args_kwargs()to properly handle*argsand**kwargsparametersSummary
Successfully fixed the bug where cachier didn't consider variadic arguments (
*args) in the cache key, causing all calls with different arguments to return the same cached result.Review Feedback Addressed
Critical Bug Fix (Comment 2730944516):
POSITIONAL_ONLYandPOSITIONAL_OR_KEYWORDparameter kindsregular_params, which would try to map positional args to themCode Simplification (Comment 2730944489):
sig.parameterswithkind == VAR_KEYWORDcannot exist as a named parameterCode Simplification (Comment 2736377566):
kwargs.update(kwds)var_keyword_namevariableTest Improvements:
test_keyword_only_parameters: Basic keyword-only parameter handlingtest_keyword_only_with_default: Keyword-only with default valuestest_mixed_varargs_keyword_only: Mixed regular, *args, and keyword-only paramsprevious_call_countbefore cache hit testsComprehensive Edge Case Coverage (Comment 3810980811):
/syntax with varargs (4 tests)Technical Details
Root Cause: The
_convert_args_kwargs()function usedzip(func_params, args)to map arguments to parameter names. For functions with*args, the parameter list only contains the parameter name (e.g.,['args']), not individual parameter names. This caused the zip to only map the first argument, losing the rest.Solution: Modified
_convert_args_kwargs()to:*args) and KEYWORD_ONLY parameters__varargs_0__,__varargs_1__, etc.)Files Changed:
src/cachier/core.py: Modified_convert_args_kwargs()function with simplified logictests/test_varargs.py: Added comprehensive test suite with 68 tests covering all edge casesTest Results:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.