Why require the keymaker to have the same signature?
johann-petrak opened this issue · 1 comments
I have a use case where pretty much all mutable unhashable objects are used immutably/read-only and where many different functions can have all kinds of such objects, mixed with hashable objects.
For this, I want to simply use the id instead of the hash (actually combine the hash and ids of all parameters into a string and hash that), so a single keymaker with signature (*args, **kwargs) would be sufficient. However the library explicitly checks and disallows to use that which means I have to implement many functions with different signatures which all do exactly the same.
Resolved in v0.4.0. Now available at PyPI or GitHub Releases.
Please upgrade by: pip install -U memoization
The explicit check that enforces the same signature policy for the user function and the custom key maker has been removed. Now, for inconsistent signatures, it will print a suppressible SyntaxWarning
:
Expected custom_key_maker to have the same signature as the function being cached.
Call memoization.suppress_warnings() before using @cached to remove this message.