INNER CODE UNIT · Python

_cachier_decorator

python-cachier/cachier · src/cachier/core.py:428

    def _cachier_decorator(func: Callable[_P, _R]) -> _CachierWrappedFunc[_P, _R]:
        core.set_func(func)

        # Guard: raise TypeError when decorating an instance method unless
        # explicitly opted in.  The 'self' parameter is ignored for cache-key
        # computation, so all instances share the same cache.
        if core.func_is_method:
            _allow_methods = _update_with_defaults(allow_non_static_methods, "allow_non_static_methods")
            if not _allow_methods:
                raise TypeError(
                    f"@cachier cannot decorate instance method "
                    f"'{func.__qualname__}' because the 'self' parameter is "
                    "excluded from cache-key computation and all instances "
                    "would share a single cache. Pass allow_non_static_methods=True "
                    "to the decorator or call "
                    "set_global_params(allow_non_static_methods=True) if "
                    "cross-instance cache sharing is intentional."
                )

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…