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
for more information, see https://pre-commit.ci
- Changed assertion to capture previous_call_count before cache hit test - Makes test explicit about verifying the count didn't increase - Consistent with other test improvements in previous commit Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
…ub.com/python-cachier/cachier into copilot/fix-cachier-varadic-args-issue
…ub.com/python-cachier/cachier into copilot/fix-cachier-varadic-args-issue
…adability and backend coverage
…adability and backend coverage
shaypal5
approved these changes
Jan 27, 2026
Contributor
|
@copilot see the codecov report and add unitests to cover the missing (edge)use-cases |
Borda
reviewed
Jan 28, 2026
- Added TestFunctoolsPartial: tests for functools.partial wrapped functions - Added TestMethodWithVarargs: tests for functions simulating method behavior - Added TestPositionalOnlyParams: tests for positional-only parameters (/) with varargs - Added TestComplexParameterMix: tests for functions with all parameter types combined - Added TestEdgeCasesEmptyAndNone: tests for None, empty strings, and zero values in varargs - Total test count increased from 42 to 68 tests (26 new tests) - All tests parametrized across pickle and memory backends for comprehensive coverage Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
Contributor
Author
Added in 79b47fd. Added 26 new edge case tests covering:
Total test count increased from 42 to 68 tests, all parametrized across pickle and memory backends. |
- Removed redundant if-else where both branches performed the same action - Simplified kwds handling to always use kwargs.update(kwds) - Removed unused var_keyword_name variable - All 68 tests still pass Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
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.