From 7df4e23b134c20fa292dbe4c35b333002e5f33f0 Mon Sep 17 00:00:00 2001 From: Simon Persson Date: Thu, 9 May 2019 19:27:31 +0200 Subject: [PATCH] Fix formatting, and add python2 support. --- beets/util/functemplate.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/beets/util/functemplate.py b/beets/util/functemplate.py index 57ea1a394..9c625b7f9 100644 --- a/beets/util/functemplate.py +++ b/beets/util/functemplate.py @@ -553,12 +553,21 @@ def _parse(template): parts.append(remainder) return Expression(parts) -@functools.lru_cache(maxsize=128) + +# Decorator that enables lru_cache on py3, and no caching on py2. +def cached(func): + if six.PY2: + # Sorry python2 users, no caching for you :( + return func + return functools.lru_cache(maxsize=128)(func) + + +@cached def template(fmt): return Template(fmt) -# External interface. +# External interface. class Template(object): """A string template, including text, Symbols, and Calls. """