I suspect some plugin code will look different by then (check demos):
(But currently training data only up to September 2021, i. e. KiCad 5.1 bindings… Maybe make sure KiCad and plugins have active mirrors on GitHub since they use it for training data.)
Hmm…, people could now understand what my code does…
# Python 2 try: from functools import cache except ImportError: def cache(function): from functools import wraps from collections import defaultdict class cachedict(defaultdict): def __missing__(self, key): self[key] = val = self.default_factory(*key) return val cache = cachedict(function) @wraps(function) def wrapper(*args): return cache[args] wrapper.cache_clear = cache.clear return wrapper # Explanation of what the code in the exception clause does
# The cache decorator is a memoization decorator. It caches the return value of the decorated function. # The first time the function is called, the return value is cached. # The next time the function is called with the same arguments, the cached value is returned. # This is useful for expensive functions that are called repeatedly with the same arguments. # The code in the exception clause is a reimplementation of the cache decorator. # It uses a defaultdict to cache the return values of the decorated function. # The defaultdict is initialized with the decorated function. # The __missing__ method of the defaultdict is overridden to call the decorated function with the missing key. # The return value of the decorated function is stored in the defaultdict and returned. # The cache is cleared by calling the cache_clear method of the wrapper function. # The cache decorator is available in Python 3.2 and later. # The code in the exception clause is a reimplementation of the cache decorator. # It is compatible with Python 2.6 and later. # It is not compatible with Python 3.2 and later. # It is not compatible with Python 3.2 and later because the cache decorator is available in Python 3.2 and later.