Category "functools"

python: clear / reset `@lru_cache` functool caching with every pytest testcase for undisturbed mocking

I combine mocking and caching in my code. The mocking is (kind of) random for each pytest as I do not know exactly, what will be returned in the real case. Henc

Test function with lru_cache decorator

I'm attempting to test a a method that is memoized through lru_cache (since it's an expensive database call). with pytest-mock. A simplified version of the cod

Python functools lru_cache with instance methods: release object

How can I use functools.lru_cache inside classes without leaking memory? In the following minimal example the foo instance won't be released although going out

functools.reduce in Python not working as expected

I would like to sum across keys of dictionaries nested within a list using the functools.reduce function I can accomplish this WITHOUT the functools.reduce func

What is the difference between partial and partialmethod?

I found out that functools module of Python 3 has two very similar methods: partial and partialmethod. Can someone provide good examples of using each one?