chore: use backported cached_property
import os
+import sys
import uuid
import random
import socket
@@ -11,6 +12,11 @@ from pathlib import Path
import fs
import fs.copy
+if sys.version_info[0] == 3 and sys.version_info[1] >= 8:
+ from functools import cached_property
+else:
+ from backports.cached_property import cached_property
+
from ..types import PathType
from .lazy_loader import LazyLoader
@@ -27,7 +33,6 @@ __all__ = [
"cached_property",
"cached_contextmanager",
"reserve_free_port",
- "get_free_port",
"catch_exceptions",
"LazyLoader",
"validate_or_create_dir",
@@ -160,30 +165,6 @@ def resolve_user_filepath(filepath: str, ctx: t.Optional[str]) -> str:
raise FileNotFoundError(f"file {filepath} not found")
-class cached_property(t.Generic[C, T]):
- """A property that is only computed once per instance and then replaces
- itself with an ordinary attribute. Deleting the attribute resets the
- property.
- """
-
- def __init__(self, func: t.Callable[[C], T]):
- try:
- functools.update_wrapper(self, func)
- except AttributeError:
- pass
- self.func = func
-
- # pylint: disable=attribute-defined-outside-init
- def __set_name__(self, owner, name):
- self.name = name
-
- def __get__(self, obj: C, cls: t.Type[C]) -> T:
- if obj is None:
- raise AttributeError(f"'{cls}' has no member '{self.name}'")
- value = obj.__dict__[self.name] = self.func(obj)
- return value
-
-
VT = t.TypeVar("VT")
