From 01bcc70e0c47fe06cdfb3417c6b184514118ab42 Mon Sep 17 00:00:00 2001 From: BJ Dierkes Date: Sun, 23 Jun 2024 20:17:40 -0500 Subject: [PATCH] Type Annotations: core.cache - Resolves Issue #693 - Related to PR #628 --- CHANGELOG.md | 1 + cement/core/cache.py | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f62ed2a9..8621bf28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ Refactoring: - `[dev]` Added Python 3.13 Dev Target - Type Annotations (related: [PR #628](https://github.com/datafolklabs/cement/pull/628)) - `[core.arg]` [Issue #692](https://github.com/datafolklabs/cement/issues/692) + - `[core.cache]` [Issue #692](https://github.com/datafolklabs/cement/issues/693) - `[core.exc]` [Issue #697](https://github.com/datafolklabs/cement/issues/697) - `[core.interface]` [Issue #702](https://github.com/datafolklabs/cement/issues/702) - `[core.meta]` [Issue #705](https://github.com/datafolklabs/cement/issues/705) diff --git a/cement/core/cache.py b/cement/core/cache.py index 501ae739..a172619b 100644 --- a/cement/core/cache.py +++ b/cement/core/cache.py @@ -1,6 +1,7 @@ """Cement core cache module.""" from abc import abstractmethod +from typing import Any, Optional from ..core.interface import Interface from ..core.handler import Handler from ..utils.misc import minimal_logger @@ -25,7 +26,7 @@ class CacheInterface(Interface): interface = 'cache' @abstractmethod - def get(self, key, fallback=None): + def get(self, key: str, fallback: Any = None) -> Any: """ Get the value for a key in the cache. @@ -47,7 +48,7 @@ class CacheInterface(Interface): pass # pragma: nocover @abstractmethod - def set(self, key, value, time=None): + def set(self, key: str, value: Any, time: Optional[int] = None) -> None: """ Set the key/value in the cache for a set amount of ``time``. @@ -66,7 +67,7 @@ class CacheInterface(Interface): pass # pragma: nocover @abstractmethod - def delete(self, key): + def delete(self, key: str) -> bool: """ Deletes a key/value from the cache. @@ -81,7 +82,7 @@ class CacheInterface(Interface): pass # pragma: nocover @abstractmethod - def purge(self): + def purge(self) -> None: """ Clears all data from the cache. @@ -95,4 +96,5 @@ class CacheHandler(CacheInterface, Handler): Cache handler implementation. """ - pass # pragma: nocover + class Meta: + pass # pragma: nocover