Skip to content

Fix memoize keys for required keyword arguments - #638

Open
jakezwang wants to merge 1 commit into
pytoolz:masterfrom
jakezwang:fix/memoize-required-keywords
Open

jakezwang wants to merge 1 commit into
pytoolz:masterfrom
jakezwang:fix/memoize-required-keywords

Conversation

@jakezwang

Copy link
Copy Markdown

memoize assumes that required parameters are passed positionally. A unary call such as memoized(x=1) raises IndexError, while calls to a binary function with different keyword arguments can share the empty-tuple cache key and return the wrong result.

Bind supplied keywords to the function signature before constructing the optimized cache key. Positional calls retain their existing keys, and equivalent positional and keyword calls share cached results.

Tests cover unary and binary functions, mixed and reordered arguments, cache reuse, and invalid keywords. The full test and doctest suites, benchmarks, style checks, and changed-file pre-commit hooks pass; tests and benchmarks also pass on Python 3.9, 3.14 and 3.15.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant