Skip to content

Commit cd89d9f

Browse files
authored
use functools.cached_property on Python>=3.12 (#270)
cached_property on Python>=3.12 does not have a lock, so we can use it instead of funcy. This means that now we don't need to depend on funcy at all for Python>=3.12, and is optional.
1 parent 63ed7de commit cd89d9f

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

pyproject.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ classifiers = [
2222
requires-python = ">=3.8"
2323
dynamic = ["version"]
2424
dependencies = [
25-
"funcy>=1.14",
25+
"funcy>=1.14; python_version < '3.12'",
2626
"fsspec>=2022.10.0",
2727
]
2828

@@ -169,8 +169,8 @@ parametrize-names-type = "csv"
169169

170170
[tool.ruff.lint.flake8-tidy-imports]
171171
[tool.ruff.lint.flake8-tidy-imports.banned-api]
172-
"funcy.cached_property" = {msg = "use `from dvc_objects.utils import cached_property` instead."}
173-
"functools.cached_property" = {msg = "use `from dvc_objects.utils import cached_property` instead."}
172+
"funcy.cached_property" = {msg = "use `from dvc_objects.compat import cached_property` instead."}
173+
"functools.cached_property" = {msg = "use `from dvc_objects.compat import cached_property` instead."}
174174

175175
[tool.ruff.lint.flake8-type-checking]
176176
strict = true

src/dvc_objects/utils.py src/dvc_objects/compat.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import sys
12
from typing import TYPE_CHECKING
23

3-
if TYPE_CHECKING:
4+
if sys.version_info >= (3, 12) or TYPE_CHECKING:
45
from functools import cached_property # noqa: TID251
56
else:
67
from funcy import cached_property # noqa: TID251

src/dvc_objects/fs/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import fsspec
3030
from fsspec.asyn import get_loop
3131

32+
from dvc_objects.compat import cached_property
3233
from dvc_objects.executors import ThreadPoolExecutor, batch_coros
33-
from dvc_objects.utils import cached_property
3434

3535
from .callbacks import (
3636
DEFAULT_CALLBACK,

src/dvc_objects/fs/local.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import logging
22
import os
33
import shutil
4-
import threading
54

65
import fsspec
7-
from funcy import wrap_prop
8-
9-
from dvc_objects.utils import cached_property
106

117
from . import system
128
from .base import FileSystem
@@ -185,10 +181,9 @@ class LocalFileSystem(FileSystem):
185181
PARAM_PATH = "path"
186182
TRAVERSE_PREFIX_LEN = 2
187183

188-
@wrap_prop(threading.Lock()) # type: ignore[misc]
189-
@cached_property
190-
def fs(self):
191-
return FsspecLocalFileSystem(**self.config)
184+
def __init__(self, fs=None, **kwargs):
185+
fs = fs or FsspecLocalFileSystem(**kwargs)
186+
super().__init__(fs, **kwargs)
192187

193188
def getcwd(self):
194189
return os.getcwd()

0 commit comments

Comments
 (0)