Skip to content

Commit

Permalink
[#35] Enabled mypy for wrapper function (and fixed issues)
Browse files Browse the repository at this point in the history
  • Loading branch information
zmumi committed Oct 4, 2024
1 parent fe90d32 commit d109a51
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-----

* Since 3.8, CancelledError is a subclass of BaseException rather than Exception, so we need to catch it explicitly.
* Enabled `mypy` for `wrapper` function.

3.1.0
-----
Expand Down
6 changes: 3 additions & 3 deletions memoize/statuses.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import datetime
import logging
from abc import ABCMeta, abstractmethod
from asyncio import Future
from asyncio import Future, CancelledError
from typing import Dict, Awaitable, Union

from memoize.entry import CacheKey, CacheEntry
Expand All @@ -30,7 +30,7 @@ def mark_updated(self, key: CacheKey, entry: CacheEntry) -> None:
raise NotImplementedError()

@abstractmethod
def mark_update_aborted(self, key: CacheKey, exception: Exception) -> None:
def mark_update_aborted(self, key: CacheKey, exception: Union[Exception, CancelledError]) -> None:
"""Informs that update failed to complete.
Calls to 'is_being_updated' will return False until 'mark_being_updated' will be called.
Accepts exception to propagate it across all clients awaiting an update."""
Expand Down Expand Up @@ -79,7 +79,7 @@ def mark_updated(self, key: CacheKey, entry: CacheEntry) -> None:
update = self._updates_in_progress.pop(key)
update.set_result(entry)

def mark_update_aborted(self, key: CacheKey, exception: Exception) -> None:
def mark_update_aborted(self, key: CacheKey, exception: Union[Exception, CancelledError]) -> None:
if key not in self._updates_in_progress:
raise ValueError('Key {} is not being updated'.format(key))
update = self._updates_in_progress.pop(key)
Expand Down
6 changes: 3 additions & 3 deletions memoize/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from memoize.statuses import UpdateStatuses, InMemoryLocks


def memoize(method: Optional[Callable] = None, configuration: CacheConfiguration = None,
invalidation: InvalidationSupport = None, update_statuses: UpdateStatuses = None):
def memoize(method: Optional[Callable] = None, configuration: Optional[CacheConfiguration] = None,
invalidation: Optional[InvalidationSupport] = None, update_statuses: Optional[UpdateStatuses] = None):
"""Wraps function with memoization.
If entry reaches time it should be updated, refresh is performed in background,
Expand Down Expand Up @@ -123,7 +123,7 @@ async def refresh(actual_entry: Optional[CacheEntry], key: CacheKey,

@functools.wraps(method)
async def wrapper(*args, **kwargs):
if not configuration.configured():
if configuration is None or not configuration.configured():
raise NotConfiguredCacheCalledException()

configuration_snapshot = MutableCacheConfiguration.initialized_with(configuration)
Expand Down
1 change: 1 addition & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[mypy]
no_implicit_optional=False
check_untyped_defs=True

0 comments on commit d109a51

Please sign in to comment.