Skip to main content

all: rename "files" to "paths" to clarify it includes files+folders

ID
b57f330
date
2026-11-26 21:16:22+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
5f1bcb9
message
all: rename "files" to "paths" to clarify it includes files+folders

While writing the README, I realised that notify_path_change and files
are inconsistent, and "path" is a better description of this
functionality.
changed files
5 files, 164 additions, 22 deletions

Changed files

CHANGELOG.md (1156 → 1550)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index fa1e69d..d6a9bd5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,14 @@
 # CHANGELOG
 
+## v1.1.0 - 2026-11-26
+
+To clarify that path dependencies include both files and folders, rename two parameters:
+
+*   When calling `cache.register()`, use `paths` instead of `files` to register path dependencies.
+*   The argument name for `notify_path_change` is `changed_paths` instead of `changed_files`.
+
+The existing parameter names are deprecated and will be removed in a future release.
+
 ## v1.0.6 - 2026-11-21
 
 Fix a bug in v1.0.5 where closing an unused lazy SQLite cache would cause the database file to be created.

README.md (7252 → 7252)

diff --git a/README.md b/README.md
index ff96b5e..5553e47 100644
--- a/README.md
+++ b/README.md
@@ -12,7 +12,7 @@ from funkycache import FunkyCache
 cache = FunkyCache(storage="sqlite")
 
 
-@cache.register(files=["templates/base.html"])
+@cache.register(paths=["templates/base.html"])
 def render_index(content: str) -> str:
     with open("templates/base.html") as f:
         template = f.read()
@@ -95,12 +95,12 @@ The `root` parameter can be a str or a [Path][pydoc-pathlib].
 
 ### Depending on an external file
 
-If your function depends on a file or folder which is not an input to the function, you can declare that dependency by passing the `files` parameter to `cache.register`.
+If your function depends on a file or folder which is not an input to the function, you can declare that dependency by passing the `paths` parameter to `cache.register`.
 
 For example, if your function depends on a template file, you can declare a dependency on the template:
 
 ```python
-@cache.register(files=["templates/greeting.html"])
+@cache.register(paths=["templates/greeting.html"])
 def render_greeting(name: str) -> str:
     template = Path("templates/greeting.html").read_text()
     return template.replace("{{ name }}", name)
@@ -129,7 +129,7 @@ If an external input file changes, you can notify funkycache by calling `cache.n
 For example:
 
 ```python
-cache.notify_path_change(changed_files=["templates/greeting.html"])
+cache.notify_path_change(changed_paths=["templates/greeting.html"])
 ```
 
 funkycache checks which registered functions depend on those paths, recomputes their input signatures, and switches affected functions to a fresh cache when the signature has changed.

src/funkycache/manager.py (20322 → 21874)

diff --git a/src/funkycache/manager.py b/src/funkycache/manager.py
index 521e820..c8f9373 100644
--- a/src/funkycache/manager.py
+++ b/src/funkycache/manager.py
@@ -16,6 +16,7 @@ import pickle
 import typing
 from typing import Any, cast, Literal, NamedTuple, overload, TypeVar
 import warnings
+from warnings import deprecated
 
 import xxhash
 
@@ -150,16 +151,27 @@ class FunkyCache:
     def register[**Params, ReturnType](
         self,
         *,
-        files: list[Path | str] | None = None,
+        paths: list[Path | str] | None = None,
         values: list[Any] | None = None,
         max_memory: int | None = None,
     ) -> Callable[[Func], Func]: ...
 
+    @overload
+    @deprecated("Use paths instead of files")
+    def register[**Params, ReturnType](
+        self,
+        *,
+        files: list[Path | str] | None = None,
+        values: list[Any] | None = None,
+        max_memory: int | None = None,
+    ) -> Callable[[Func], Func] | Func: ...
+
     def register[**Params, ReturnType](
         self,
         func: Func | None = None,
         *,
         files: list[Path | str] | None = None,
+        paths: list[Path | str] | None = None,
         values: list[Any] | None = None,
         max_memory: int | None = None,
     ) -> Callable[[Func], Func] | Func:
@@ -178,10 +190,16 @@ class FunkyCache:
         The memory budget is an approximate, best-effort limit in bytes.
         It's a soft cap, and may be slightly exceeded.
         """
+        if files is not None and paths is not None:
+            raise TypeError("Do not pass both files and paths.")
+
+        if files is not None:
+            warnings.warn("Use paths instead of folders.", DeprecationWarning)
+            paths = files
 
         def decorator(func: Func) -> Func:
             data_type = _data_type(func, self._storage)
-            dep_paths = _dep_paths(func, files=[Path(p) for p in (files or [])])
+            dep_paths = _dep_paths(func, paths=[Path(p) for p in (paths or [])])
             dep_values = values or []
 
             if any(
@@ -324,11 +342,27 @@ class FunkyCache:
             case _:
                 pass
 
+    @overload
+    def notify_path_change(
+        self, changed_paths: Path | str | Sequence[Path | str] | None
+    ) -> None: ...
+
+    @deprecated("Use changed_files instead of changed_paths.")
+    @overload
+    def notify_path_change(
+        self,
+        *,
+        changed_files: Path | str | Sequence[Path | str] | None,
+    ) -> None: ...
+
     def notify_path_change(
-        self, changed_paths: Path | str | Sequence[Path | str]
+        self,
+        changed_paths: Path | str | Sequence[Path | str] | None = None,
+        *,
+        changed_files: Path | str | Sequence[Path | str] | None = None,
     ) -> None:
         """
-        Invalidate cache that depend on this path and/or paths.
+        Invalidate caches that depend on this path and/or paths.
 
         Call this after modifying files that a cached function depends on.
         The function's cache will be invalidated, and the next call will
@@ -339,6 +373,18 @@ class FunkyCache:
         on actually change, so notifying about an unrelated or unchanged
         path is cheap and safe.
         """
+        if changed_files is not None and changed_paths is not None:
+            raise TypeError("Do not pass both changed_paths and changed_files.")
+
+        if changed_files is not None:
+            warnings.warn(
+                "Use changed_paths instead of changed_files.", DeprecationWarning
+            )
+            changed_paths = changed_files
+
+        if changed_paths is None:
+            raise TypeError("You must pass a non-empty list of changed paths.")
+
         # Convert input values to a list of absolute paths.
         if isinstance(changed_paths, (Path, str)):
             changed_paths = [changed_paths]
@@ -435,7 +481,7 @@ def _data_type(func: Func, storage: StorageType) -> Any:
     return ret_annotation
 
 
-def _dep_paths(func: Func, files: list[Path]) -> set[Path]:
+def _dep_paths(func: Func, paths: list[Path]) -> set[Path]:
     """
     Get a list of all the absolute paths this function depends on.
     """
@@ -450,9 +496,9 @@ def _dep_paths(func: Func, files: list[Path]) -> set[Path]:
             "caches may not be invalidated correctly"
         )
 
-    # 2. Include any explicitly declared files.
-    if files:
-        dep_paths.extend([p.resolve() for p in files])
+    # 2. Include any explicitly declared paths.
+    if paths:
+        dep_paths.extend([p.resolve() for p in paths])
 
     return set(dep_paths)
 

src/funkycache/version.py (55 → 55)

diff --git a/src/funkycache/version.py b/src/funkycache/version.py
index d066fba..7103e33 100644
--- a/src/funkycache/version.py
+++ b/src/funkycache/version.py
@@ -2,4 +2,4 @@
 The FunkyCache version.
 """
 
-__version__ = "1.0.6"
+__version__ = "1.1.0"

tests/test_manager.py (32412 → 35600)

diff --git a/tests/test_manager.py b/tests/test_manager.py
index 1f7c438..fbac93e 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -317,7 +317,7 @@ class FunkyCacheTestSuite(ABC):
             pytest.param(lambda p: {str(p)}, id="s-str"),
         ],
     )
-    def test_cache_invalidated_on_path_change(
+    def test_cache_depends_on_paths(
         self,
         cache: FunkyCache,
         tmp_path: Path,
@@ -333,7 +333,7 @@ class FunkyCacheTestSuite(ABC):
         # Count how many times the underlying function was called
         calls = Counter[str]()
 
-        @cache.register(files=[p])
+        @cache.register(paths=[p])
         def initial(s: str) -> str:
             calls[s] += 1
             return s[0].upper()
@@ -368,7 +368,7 @@ class FunkyCacheTestSuite(ABC):
         # Count how many times the underlying function was called
         calls = Counter[str]()
 
-        @cache.register(files=[p])
+        @cache.register(paths=[p])
         def initial(s: str) -> str:
             calls[s] += 1
             return s[0].upper()
@@ -400,7 +400,7 @@ class FunkyCacheTestSuite(ABC):
         # Count how many times the underlying function was called
         calls = Counter[str]()
 
-        @cache.register(files=[tmp_path / "messages"])
+        @cache.register(paths=[tmp_path / "messages"])
         def initial(s: str) -> str:
             calls[s] += 1
             return s[0].upper()
@@ -490,7 +490,7 @@ class FunkyCacheTestSuite(ABC):
         will be created later.
         """
 
-        @cache.register(files=[tmp_path / "does_not_exist"])
+        @cache.register(paths=[tmp_path / "does_not_exist"])
         def double(n: int) -> int:
             return n * 2
 
@@ -516,7 +516,7 @@ class FunkyCacheTestSuite(ABC):
             # Count how many times the underlying function was called
             calls = Counter[str]()
 
-            @cache.register(files=[modify_depends_on(p)])
+            @cache.register(paths=[modify_depends_on(p)])
             def initial(s: str) -> str:
                 calls[s] += 1
                 return s[0].upper()
@@ -810,7 +810,7 @@ class TestSQLiteFunkyCache(FunkyCacheTestSuite):
         greeting1 = "bonjour monde"
         greeting2 = "hello world"
 
-        @c.register(files=[p])
+        @c.register(paths=[p])
         def get_size() -> int:
             return Path(p).stat().st_size
 
@@ -950,13 +950,13 @@ class TestSQLiteFunkyCache(FunkyCacheTestSuite):
         with contextlib.chdir(tmp_path):
             cache = FunkyCache(storage="sqlite", root=modify_root(root))
 
-            files: list[Path | str] = [modify_depends_on(depends_on(root))]
+            paths: list[Path | str] = [modify_depends_on(depends_on(root))]
 
             with pytest.raises(
                 ValueError, match="cannot depend on a file/folder inside the cache root"
             ):
 
-                @cache.register(files=files)
+                @cache.register(paths=paths)
                 def double(n: int) -> int:  # pragma: no cover
                     return n * 2
 
@@ -981,3 +981,90 @@ class TestSQLiteFunkyCache(FunkyCacheTestSuite):
         # Creating a cache entry creates the db
         assert greet("Alex") == "Hello Alex!"
         assert cache_root.exists()
+
+
+class TestFunkyCacheFilesNotPaths:
+    """
+    In v1.0, path dependencies were declared with a `files/changed_files`
+    argument, which I renamed to `paths/changed_paths` in v1.1.
+
+    This test checks that all the old behaviour works, and that it emits
+    the correct deprecation warnings.
+
+    If I ever do a v2 and remove the old parameters, I can delete this test.
+    """
+
+    @pytest.fixture
+    def cache(self) -> Iterator[FunkyCache]:
+        """
+        Return an empty instance of FunkyCache.
+        """
+        yield FunkyCache(storage="memory")
+
+    def test_depends_on_paths(self, cache: FunkyCache, tmp_path: Path) -> None:
+        """
+        You can register a function which depends on files, and it behaves
+        the same way as paths.
+        """
+        p = tmp_path / "greeting.txt"
+        p.write_text("hello world!")
+
+        # Count how many times the underlying function was called
+        calls = Counter[str]()
+
+        with pytest.warns(match="Use paths instead of folders"):
+
+            @cache.register(files=[p])  # ty: ignore[deprecated]
+            def initial(s: str) -> str:
+                calls[s] += 1
+                return s[0].upper()
+
+        # The first call is a cache miss; goes to the real function
+        assert initial("apple") == "A"
+        assert calls == {"apple": 1}
+
+        # The second call is a cache hit; skips the real function
+        assert initial("apple") == "A"
+        assert calls == {"apple": 1}
+
+        # Change the underlying file
+        p.write_text("bonjour monde")
+
+        with pytest.warns(match="Use changed_paths instead of changed_files"):
+            cache.notify_path_change(changed_files=[p])  # ty: ignore[deprecated]
+
+        # The third call is a cache miss; goes to the real function
+        assert initial("apple") == "A"
+        assert calls == {"apple": 2}
+
+    def test_cannot_pass_files_and_paths(self, cache: FunkyCache) -> None:
+        """
+        You can't register a function with both file and path dependencies.
+        """
+        with pytest.raises(TypeError, match="Do not pass both files and paths"):
+
+            @cache.register(files=["greetings.txt"], paths=["names.txt"])  # ty: ignore[no-matching-overload]
+            def greet(name: str) -> str:  # pragma: no cover
+                return f"Hello {name}!"
+
+    def test_cannot_notify_files_and_paths(self, cache: FunkyCache) -> None:
+        """
+        You can't call notify_path_change with both files and paths.
+        """
+        with pytest.raises(
+            TypeError, match="Do not pass both changed_paths and changed_files"
+        ):
+            cache.notify_path_change(
+                changed_files=["greeting.txt"],
+                changed_paths=["names.txt"],
+            )  # ty: ignore[no-matching-overload]
+
+    def test_neither_paths_nor_files_is_error(self, cache: FunkyCache) -> None:
+        """
+        You can't call notify_path_change without passing one of
+        changed_paths or changed_files.
+        """
+        with pytest.raises(
+            TypeError, match="You must pass a non-empty list of changed paths"
+        ):
+            cache.notify_path_change()  # ty: ignore[no-matching-overload]