Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
ytausch committed Feb 13, 2024
1 parent 755fed1 commit 99fb4a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
18 changes: 9 additions & 9 deletions conda_forge_tick/lazy_json_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ def get_sharded_path(file_path, n_dirs=5):
class LazyJsonBackend(ABC):
@contextlib.contextmanager
@abstractmethod
def transaction_context(self) -> "LazyJsonBackend":
def transaction_context(self) -> "Iterator[LazyJsonBackend]":
pass

@contextlib.contextmanager
@abstractmethod
def snapshot_context(self) -> "LazyJsonBackend":
def snapshot_context(self) -> "Iterator[LazyJsonBackend]":
pass

@abstractmethod
Expand Down Expand Up @@ -108,12 +108,12 @@ def hgetall(self, name: str, hashval: bool = False) -> Dict[str, str]:

class FileLazyJsonBackend(LazyJsonBackend):
@contextlib.contextmanager
def transaction_context(self) -> "FileLazyJsonBackend":
def transaction_context(self) -> "Iterator[FileLazyJsonBackend]":
# context not required
yield self

@contextlib.contextmanager
def snapshot_context(self) -> "FileLazyJsonBackend":
def snapshot_context(self) -> "Iterator[FileLazyJsonBackend]":
# context not required
yield self

Expand All @@ -131,7 +131,7 @@ def hmset(self, name: str, mapping: Mapping[str, str]) -> None:
for key, value in mapping.items():
self.hset(name, key, value)

def hmget(self, name: str, keys: str) -> List[str]:
def hmget(self, name: str, keys: Iterable[str]) -> List[str]:
return [self.hget(name, key) for key in keys]

def hgetall(self, name: str, hashval: bool = False) -> Dict[str, str]:
Expand Down Expand Up @@ -222,11 +222,11 @@ def _inform_web_request(cls):
f"Using the GitHub online backend for making a lot of requests is not recommended.",
)

def transaction_context(self) -> "GithubLazyJsonBackend":
def transaction_context(self) -> "Iterator[GithubLazyJsonBackend]":
# context not required
yield self

def snapshot_context(self) -> "GithubLazyJsonBackend":
def snapshot_context(self) -> "Iterator[GithubLazyJsonBackend]":
# context not required
yield self

Expand Down Expand Up @@ -318,7 +318,7 @@ class MongoDBLazyJsonBackend(LazyJsonBackend):
_snapshot_session = None

@contextlib.contextmanager
def transaction_context(self):
def transaction_context(self) -> "Iterator[MongoDBLazyJsonBackend]":
try:
if self.__class__._session is None:
client = get_graph_data_mongodb_client()
Expand All @@ -333,7 +333,7 @@ def transaction_context(self):
self.__class__._session = None

@contextlib.contextmanager
def snapshot_context(self):
def snapshot_context(self) -> "Iterator[MongoDBLazyJsonBackend]":
try:
if self.__class__._snapshot_session is None:
client = get_graph_data_mongodb_client()
Expand Down
6 changes: 0 additions & 6 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def test_load_graph():

assert gx.nodes.keys() == {"package1", "package2"}

mock_file: MagicMock
mock_file.assert_has_calls([mock.call(DEFAULT_GRAPH_FILENAME)])


Expand All @@ -102,7 +101,6 @@ def test_load_graph_empty_graph():

assert gx is None

mock_file: MagicMock
mock_file.assert_has_calls([mock.call(DEFAULT_GRAPH_FILENAME)])


Expand All @@ -113,7 +111,6 @@ def test_load_graph_file_does_not_exist(exists_mock: MagicMock):
with mock.patch("builtins.open", mock_open(read_data=EMPTY_JSON)) as mock_file:
load_graph()

mock_file: MagicMock
mock_file.assert_has_calls([mock.call(DEFAULT_GRAPH_FILENAME, "w")])


Expand All @@ -123,7 +120,6 @@ def test_load_existing_graph():

assert gx.nodes.keys() == {"package1", "package2"}

mock_file: MagicMock
mock_file.assert_has_calls([mock.call(DEFAULT_GRAPH_FILENAME)])


Expand All @@ -132,7 +128,6 @@ def test_load_existing_graph_empty_graph():
with pytest.raises(ValueError, match="empty JSON"):
load_existing_graph()

mock_file: MagicMock
mock_file.assert_has_calls([mock.call(DEFAULT_GRAPH_FILENAME)])


Expand All @@ -144,5 +139,4 @@ def test_load_existing_graph_file_does_not_exist(exists_mock: MagicMock):
with pytest.raises(ValueError, match="empty JSON"):
load_existing_graph()

mock_file: MagicMock
mock_file.assert_has_calls([mock.call(DEFAULT_GRAPH_FILENAME, "w")])

0 comments on commit 99fb4a0

Please sign in to comment.