Skip to content

Commit

Permalink
Fix mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
Stranger6667 committed Jan 9, 2020
1 parent d77e21f commit 2697aaa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/konfetti/cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime, timedelta
from typing import Dict, Optional, Union
from typing import Dict, Optional, Union, cast, Any

import attr

Expand Down Expand Up @@ -91,6 +91,7 @@ def get(self, key):
data = self._data.get(key, EMPTY)
if data is EMPTY:
return data
data = cast(Dict[str, Any], data)
if self._delete_if_expired(key, data["inserted"]):
return EMPTY
return data["data"]
Expand Down
5 changes: 3 additions & 2 deletions src/konfetti/laziness.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@attr.s(slots=True)
class LazyVariable(DefaultMixin, CastableMixin):
name = attr.ib(default=NOT_SET)
func = attr.ib(default=NOT_SET)
func = attr.ib(default=NOT_SET, type=Callable)
default = attr.ib(default=NOT_SET)
cast = attr.ib(default=NOT_SET, validator=validate_cast)

Expand All @@ -38,7 +38,8 @@ def __call__(self, func):
self.func = func
name = func.__module__.rsplit(".", 1)[1]
module = __import__(func.__module__, fromlist=[name])
setattr(module, self.name, self)
# NOTE. It is better to prevent usage of `lazy` without a passed name
setattr(module, self.name, self) # type: ignore
return self

def evaluate(self, config):
Expand Down
8 changes: 5 additions & 3 deletions src/konfetti/vault/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, Union # ignore: PyUnusedCodeBear
from typing import Optional, Union, cast # ignore: PyUnusedCodeBear

import attr

Expand Down Expand Up @@ -40,12 +40,14 @@ def _get_full_path(self, path):

def _get_from_cache(self, path):
if self.cache is not NOT_SET:
return self.cache.get(path)
cache = cast(InMemoryCache, self.cache)
return cache.get(path)
return EMPTY

def _set_to_cache(self, path, value):
if self.cache is not NOT_SET:
self.cache.set(path, value)
cache = cast(InMemoryCache, self.cache)
cache.set(path, value)

def _get_retry(self, cls, exception):
retry = self.retry
Expand Down

0 comments on commit 2697aaa

Please sign in to comment.