cached-method
What it does
Section titled “What it does”Reports a method decorated with functools.lru_cache or functools.cache. Static methods are not reported.
Why it matters
Section titled “Why it matters”The cache belongs to the function and is shared by all instances. It stores self as part of each key, so an instance that called the method stays alive until its entry is evicted, and with no size limit (functools.cache, maxsize=None) for as long as the cache does.
To fix, keep the cache per instance (create it in __init__), use functools.cached_property, or move the work to a function that takes only the values it needs.
Example
Section titled “Example”...
import functools... @functools.cache def f(self): pass
...Configuration
Section titled “Configuration”python: lint: rules: cached-method: warn # off, warn (default), errorEnabled by the presets: python/ruff.
Suppress one line with sudsy-disable-next-line cached-method in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| ruff | B019 |
full |