Re:So Google's Gemini Doesn't Like Python Programming and Sa...
by amingilani on Sunday February 25, 2024 @05:09PM
(#39505391)
The modern way is to use @cache which is just lru_cache(maxsize=None).
Re:So Google's Gemini Doesn't Like Python Programming and Sa...
by epwr on Sunday February 25, 2024 @05:43PM
(#39505692)
lru_cache has the benefit of being explicit about the replacement policy. So I find it more appropriate in cases where I want a size limit in the cache which, for me, is almost always.
I’m not sure use cases you see caches in, but any long running process should likely have a size limit on the cache.
Re:So Google's Gemini Doesn't Like Python Programming and Sa...
by curiousgal on Sunday February 25, 2024 @05:26PM
(#39505544)
It still doesn't sit right with me that they still don't offer an option to enable deep copying the results. Using it with a function that returns a mutable object means that the "cached" value can actually be modified.
Re:So Google's Gemini Doesn't Like Python Programming and Sa...
by geysersam on Sunday February 25, 2024 @05:36PM
(#39505636)
That depends on the semantics. If the function returns the Person object with a particular name (obtained from an expensive dB query) then you want the mutated Person returned, not the now stale value that was returned on the previous call to the function.
Re:So Google's Gemini Doesn't Like Python Programming and Sa...
by o11c on Sunday February 25, 2024 @06:04PM
(#39505866)
Because deep copying is always a bug. If your type semantically requires a deep copy, implement plain copy such that it actually does a deep copy.
Re:So Google's Gemini Doesn't Like Python Programming and Sa...
by rational_indian on Sunday February 25, 2024 @05:02PM
(#39505304)
I know decorators can be used to auto-memoise function arguments but I've never heard of @lru_cache for python.
I am still surprised you are not familiar with @lru_cache when you want to write about decorators in Python.