{"id":6649,"library":"functools32","title":"functools32","description":"functools32 is a backport of the `functools` standard library module from Python 3.2.3, designed for use with Python 2.7 and PyPy. Its primary purpose is to provide features like `lru_cache` (Least-recently-used cache decorator) to older Python environments that lack them natively. The library saw its last release in July 2015 and is no longer actively maintained, as its features are standard in Python 3+ versions.","status":"deprecated","version":"3.2.3-2","language":"en","source_language":"en","source_url":"https://github.com/MiCHiLU/python-functools32","tags":["python2","backport","functools","lru_cache","pypy"],"install":[{"cmd":"pip install functools32","lang":"bash","label":"Install for Python 2.7 / PyPy"}],"dependencies":[{"reason":"The library is a backport specifically for these older Python runtimes and is not intended for Python 3.","package":"Python 2.7 or PyPy","optional":false}],"imports":[{"note":"After installing functools32, its features are intended to be imported directly from the standard `functools` module, as it effectively replaces or augments the built-in module on Python 2.7/PyPy.","wrong":"from functools32 import lru_cache","symbol":"lru_cache","correct":"from functools import lru_cache"},{"note":"Like lru_cache, other backported features are imported directly from `functools`.","symbol":"partial","correct":"from functools import partial"}],"quickstart":{"code":"import sys\n# This library is only for Python 2.7/PyPy.\n# For modern Python, functools.lru_cache is built-in.\nif sys.version_info.major < 3:\n    import functools\n    from functools import lru_cache\n    import time\n\n    @lru_cache(maxsize=128)\n    def fibonacci(n):\n        if n < 2:\n            return n\n        return fibonacci(n - 1) + fibonacci(n - 2)\n\n    print(f\"Calculating fibonacci(30) on Python {sys.version_info.major}.{sys.version_info.minor}...\")\n    start = time.time()\n    result = fibonacci(30)\n    end = time.time()\n    print(f\"fibonacci(30) = {result}, took {end - start:.4f} seconds\")\n    print(f\"Cache info: {fibonacci.cache_info()}\")\nelse:\n    print(f\"functools32 is not needed on Python {sys.version_info.major}.{sys.version_info.minor}. Use built-in functools.\")","lang":"python","description":"This example demonstrates how to use the `lru_cache` decorator provided by functools32 on Python 2.7. For Python 3 and newer, `lru_cache` is part of the standard `functools` module and `functools32` should not be used."},"warnings":[{"fix":"Do not install or use functools32 on Python 3. For Python 3, directly `import functools` to access features like `lru_cache`.","message":"functools32 is strictly for Python 2.7 and PyPy. Attempting to install or use it on Python 3 will lead to errors, as the functionality it provides is already built into Python 3's standard `functools` module.","severity":"breaking","affected_versions":"Python 3.x"},{"fix":"Migrate Python 2.7 applications to Python 3, where `functools` provides these features natively and is actively maintained.","message":"The entire library is considered deprecated due to Python 2.7 reaching its end-of-life and the complete integration of its features into modern Python 3. No further development or maintenance is expected.","severity":"deprecated","affected_versions":"All versions"},{"fix":"Ensure that all arguments passed to an `lru_cache` decorated function are immutable and hashable. If mutable data must be used, convert it to an immutable representation (e.g., tuple, frozenset) before passing it to the cached function.","message":"Using mutable arguments (e.g., lists, dictionaries) with `lru_cache` will result in a `TypeError: unhashable type` because cached function arguments must be hashable to serve as dictionary keys.","severity":"gotcha","affected_versions":"All versions (general `lru_cache` behavior)"},{"fix":"For critical scenarios requiring strict single-call execution or for `cached_property` in multi-threaded contexts, implement explicit locking within the decorated function or around the cached property access.","message":"While `lru_cache` is thread-safe for basic usage, a race condition can occur where the decorated function might be called more than once by different threads if an initial call has not yet completed and cached its result. `cached_property` in newer `functools` also has similar considerations.","severity":"gotcha","affected_versions":"All versions (general `lru_cache` behavior)"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}