]> jfr.im git - yt-dlp.git/blame - yt_dlp/compat/functools.py
[compat] Add `functools.cached_property`
[yt-dlp.git] / yt_dlp / compat / functools.py
CommitLineData
0b9c08b4 1# flake8: noqa: F405
2from functools import * # noqa: F403
3
4from .compat_utils import passthrough_module
5
6passthrough_module(__name__, 'functools')
7del passthrough_module
8
9try:
10 cache # >= 3.9
11except NameError:
12 cache = lru_cache(maxsize=None)
2762dbb1 13
14try:
15 cached_property # >= 3.8
16except NameError:
17 class cached_property:
18 def __init__(self, func):
19 update_wrapper(self, func)
20 self.func = func
21
22 def __get__(self, instance, _):
23 setattr(instance, self.func.__name__, self.func(instance))
24 return getattr(instance, self.func.__name__)