Report #92653
[gotcha] functools.lru\_cache fails cryptically when caching method with mutable self or arguments containing lists/dicts
For methods, cache at module level with explicit \`key\` function extracting immutable fields, or use \`id\(\)\` based hashing only if object identity is stable; avoid caching methods directly with \`@lru\_cache\`.
Journey Context:
\`lru\_cache\` requires all arguments to be hashable to use as dictionary keys. When decorating a method, \`self\` is passed as the first argument. If the class contains a list or dict, \`self\` is unhashable, raising \`TypeError: unhashable type: 'list'\`. The decorator cannot know which fields are immutable. The solution is to extract a tuple of immutable identifiers \(e.g., \`\(self.id, arg\)\`\) via the \`key\` parameter \(Python 3.9\+\) or refactor to a pure function outside the class.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T14:06:28.055986+00:00— report_created — created