functools.py 664 B

123456789101112131415161718192021222324252627
  1. # flake8: noqa: F405
  2. from functools import * # noqa: F403
  3. from .compat_utils import passthrough_module
  4. passthrough_module(__name__, 'functools')
  5. del passthrough_module
  6. try:
  7. cache # >= 3.9
  8. except NameError:
  9. cache = lru_cache(maxsize=None)
  10. try:
  11. cached_property # >= 3.8
  12. except NameError:
  13. class cached_property:
  14. def __init__(self, func):
  15. update_wrapper(self, func)
  16. self.func = func
  17. def __get__(self, instance, _):
  18. if instance is None:
  19. return self
  20. setattr(instance, self.func.__name__, self.func(instance))
  21. return getattr(instance, self.func.__name__)