Skip to content

Commit c55b969

Browse files
committed
Add some type hints
1 parent 079a156 commit c55b969

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

vdirsyncer/sync/__init__.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import itertools
1414
import logging
1515

16+
from vdirsyncer.storage.base import Storage
17+
from vdirsyncer.vobject import Item
18+
1619
from ..exceptions import UserError
1720
from ..utils import uniq
1821
from .exceptions import BothReadOnly
@@ -21,6 +24,7 @@
2124
from .exceptions import StorageEmpty
2225
from .exceptions import SyncConflict
2326
from .status import ItemMetadata
27+
from .status import SqliteStatus
2428
from .status import SubStatus
2529

2630
sync_logger = logging.getLogger(__name__)
@@ -30,22 +34,22 @@ class _StorageInfo:
3034
"""A wrapper class that holds prefetched items, the status and other
3135
things."""
3236

33-
def __init__(self, storage, status):
37+
def __init__(self, storage: Storage, status: SubStatus):
3438
self.storage = storage
3539
self.status = status
36-
self._item_cache = {}
40+
self._item_cache = {} # type: ignore[var-annotated]
3741

38-
async def prepare_new_status(self):
42+
async def prepare_new_status(self) -> bool:
3943
storage_nonempty = False
4044
prefetch = []
4145

42-
def _store_props(ident, props):
46+
def _store_props(ident: str, props: ItemMetadata) -> None:
4347
try:
4448
self.status.insert_ident(ident, props)
4549
except IdentAlreadyExists as e:
4650
raise e.to_ident_conflict(self.storage)
4751

48-
async for href, etag in self.storage.list():
52+
async for href, etag in self.storage.list(): # type: ignore[attr-defined]
4953
storage_nonempty = True
5054
ident, meta = self.status.get_by_href(href)
5155

@@ -68,7 +72,7 @@ def _store_props(ident, props):
6872

6973
return storage_nonempty
7074

71-
def is_changed(self, ident):
75+
def is_changed(self, ident: str) -> bool:
7276
old_meta = self.status.get(ident)
7377
if old_meta is None: # new item
7478
return True
@@ -81,30 +85,28 @@ def is_changed(self, ident):
8185
and (old_meta.hash is None or new_meta.hash != old_meta.hash)
8286
)
8387

84-
def set_item_cache(self, ident, item):
88+
def set_item_cache(self, ident, item) -> None:
8589
actual_hash = self.status.get_new(ident).hash
8690
assert actual_hash == item.hash
8791
self._item_cache[ident] = item
8892

89-
def get_item_cache(self, ident):
93+
def get_item_cache(self, ident: str) -> Item:
9094
return self._item_cache[ident]
9195

9296

9397
async def sync(
94-
storage_a,
95-
storage_b,
96-
status,
98+
storage_a: Storage,
99+
storage_b: Storage,
100+
status: SqliteStatus,
97101
conflict_resolution=None,
98102
force_delete=False,
99103
error_callback=None,
100104
partial_sync="revert",
101-
):
105+
) -> None:
102106
"""Synchronizes two storages.
103107
104108
:param storage_a: The first storage
105-
:type storage_a: :class:`vdirsyncer.storage.base.Storage`
106109
:param storage_b: The second storage
107-
:type storage_b: :class:`vdirsyncer.storage.base.Storage`
108110
:param status: {ident: (href_a, etag_a, href_b, etag_b)}
109111
metadata about the two storages for detection of changes. Will be
110112
modified by the function and should be passed to it at the next sync.

0 commit comments

Comments
 (0)