Using `@functools.lru_cache` on an instance method behaves in interesting ways. The cache kept a ref around for `self`, so in effect we were never GC-ing keystore objects. Effectively there was a single global cache for derive_pubkey, with keys `(keystore, for_change, n)`. This PR now changes the caching to be per-keystore: each ks has a cache, keyed `(for_change, n)`. GC-ing individual keystores should now be possible, which should result in cleaning up just their own cache. This also enables the corresponding previously silence flake8-bugbear check for `@functools.lru_cache`. (note that the check can selectively be disabled by adding a comment on the relevant line: `# noqa: B019`)
14 KiB
14 KiB