diff --git a/beets/library.py b/beets/library.py index 367b184ef..90841c493 100644 --- a/beets/library.py +++ b/beets/library.py @@ -22,6 +22,7 @@ import string import sys import time import unicodedata +from functools import cached_property from mediafile import MediaFile, UnreadableFileError @@ -31,7 +32,6 @@ from beets.dbcore import Results, types from beets.util import ( MoveOperation, bytestring_path, - lazy_property, normpath, samefile, syspath, @@ -436,11 +436,11 @@ class FormattedItemMapping(dbcore.db.FormattedMapping): self.model_keys = included_keys self.item = item - @lazy_property + @cached_property def all_keys(self): return set(self.model_keys).union(self.album_keys) - @lazy_property + @cached_property def album_keys(self): album_keys = [] if self.album: diff --git a/beets/util/__init__.py b/beets/util/__init__.py index 916abddde..72fc15f0f 100644 --- a/beets/util/__init__.py +++ b/beets/util/__init__.py @@ -16,7 +16,6 @@ import errno import fnmatch -import functools import os import platform import re @@ -1106,26 +1105,3 @@ def par_map(transform: Callable, items: Iterable): pool.map(transform, items) pool.close() pool.join() - - -def lazy_property(func: Callable) -> Callable: - """A decorator that creates a lazily evaluated property. On first access, - the property is assigned the return value of `func`. This first value is - stored, so that future accesses do not have to evaluate `func` again. - - This behaviour is useful when `func` is expensive to evaluate, and it is - not certain that the result will be needed. - """ - field_name = "_" + func.__name__ - - @property - @functools.wraps(func) - def wrapper(self): - if hasattr(self, field_name): - return getattr(self, field_name) - - value = func(self) - setattr(self, field_name, value) - return value - - return wrapper