]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/compat/functools.py
[compat] Add `functools.cached_property`
[yt-dlp.git] / yt_dlp / compat / functools.py
index 36c983642df1fa494815ce72ec6de77838e5f9d1..c3c4d8f486af3ffa5ec0a50550ed5d65e241e0f2 100644 (file)
     cache  # >= 3.9
 except NameError:
     cache = lru_cache(maxsize=None)
+
+try:
+    cached_property  # >= 3.8
+except NameError:
+    class cached_property:
+        def __init__(self, func):
+            update_wrapper(self, func)
+            self.func = func
+
+        def __get__(self, instance, _):
+            setattr(instance, self.func.__name__, self.func(instance))
+            return getattr(instance, self.func.__name__)