From 5432fcebee360a26e905d6c3c7ee2b481bae013b Mon Sep 17 00:00:00 2001 From: allen0099 Date: Tue, 29 Sep 2026 14:49:21 +0000 Subject: [PATCH] feat!: remove the unused CacheError exception fastapi_cachex.exceptions.CacheError was never raised and has emitted a DeprecationWarning since 0.3.8. Catch CacheXError instead. Closes #130 --- changelog.d/130.removed.md | 3 +++ docs/api/types.md | 4 ---- fastapi_cachex/exceptions.py | 32 -------------------------------- tests/test_exceptions.py | 35 ----------------------------------- 4 files changed, 3 insertions(+), 71 deletions(-) create mode 100644 changelog.d/130.removed.md delete mode 100644 tests/test_exceptions.py diff --git a/changelog.d/130.removed.md b/changelog.d/130.removed.md new file mode 100644 index 0000000..7fe48fb --- /dev/null +++ b/changelog.d/130.removed.md @@ -0,0 +1,3 @@ +**`fastapi_cachex.exceptions.CacheError` is removed.** Nothing in the package +ever raised it, and it had emitted a `DeprecationWarning` since 0.3.8. Catch +`CacheXError` instead. diff --git a/docs/api/types.md b/docs/api/types.md index b1b25cb..5bd2647 100644 --- a/docs/api/types.md +++ b/docs/api/types.md @@ -3,7 +3,3 @@ ::: fastapi_cachex.types ::: fastapi_cachex.exceptions - -`fastapi_cachex.exceptions.CacheError` is deprecated since 0.3.8 and not listed -above. Nothing in the package raises it, and accessing it emits a -`DeprecationWarning`. Catch `CacheXError` instead. It will be removed in 0.4.0. diff --git a/fastapi_cachex/exceptions.py b/fastapi_cachex/exceptions.py index ead9a89..adbcc5d 100644 --- a/fastapi_cachex/exceptions.py +++ b/fastapi_cachex/exceptions.py @@ -1,28 +1,10 @@ """Custom exception classes for FastAPI-CacheX.""" -import warnings -from typing import TYPE_CHECKING - class CacheXError(Exception): """Base class for all exceptions in FastAPI-CacheX.""" -class _CacheError(CacheXError): - """Exception raised for cache-related errors. - - .. deprecated:: 0.3.8 - Never raised by FastAPI-CacheX. Catch :class:`CacheXError` instead. - Will be removed in version 0.4.0. - """ - - -_CacheError.__name__ = _CacheError.__qualname__ = "CacheError" - -if TYPE_CHECKING: - CacheError = _CacheError - - class BackendNotFoundError(CacheXError): """Exception raised when a cache backend is not found.""" @@ -42,17 +24,3 @@ class RequestNotFoundError(CacheXError): class LockTimeoutError(CacheXError, TimeoutError): """Exception raised when acquiring a lock or waiting for stampede protection times out.""" - - -def __getattr__(name: str) -> type[CacheXError]: - """Return the deprecated ``CacheError`` with a ``DeprecationWarning``.""" - if name == "CacheError": - warnings.warn( - "CacheError is deprecated and never raised, catch CacheXError instead. " - "Will be removed in version 0.4.0.", - DeprecationWarning, - stacklevel=2, - ) - return _CacheError - msg = f"module {__name__!r} has no attribute {name!r}" - raise AttributeError(msg) diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py deleted file mode 100644 index 2756b05..0000000 --- a/tests/test_exceptions.py +++ /dev/null @@ -1,35 +0,0 @@ -"""Tests for the package-level exceptions.""" - -import importlib - -import pytest - -from fastapi_cachex.exceptions import CacheXError - - -def test_cache_error_access_warns_and_still_works() -> None: - """Test accessing the deprecated CacheError warns (#163).""" - exceptions = importlib.import_module("fastapi_cachex.exceptions") - - with pytest.warns(DeprecationWarning, match="CacheError is deprecated") as record: - cache_error = exceptions.CacheError - - assert record[0].filename == __file__ - assert cache_error.__name__ == "CacheError" - assert issubclass(cache_error, CacheXError) - with pytest.raises(CacheXError): - raise cache_error - - -def test_cache_error_from_import_warns() -> None: - """Test ``from fastapi_cachex.exceptions import CacheError`` warns (#163).""" - with pytest.warns(DeprecationWarning, match="removed in version 0.4.0"): - from fastapi_cachex.exceptions import CacheError # noqa: F401 - - -def test_unknown_attribute_still_raises_attribute_error() -> None: - """Test the module ``__getattr__`` only handles CacheError.""" - exceptions = importlib.import_module("fastapi_cachex.exceptions") - - with pytest.raises(AttributeError, match="has no attribute 'Missing'"): - _ = exceptions.Missing