1313import itertools
1414import logging
1515
16+ from vdirsyncer .storage .base import Storage
17+ from vdirsyncer .vobject import Item
18+
1619from ..exceptions import UserError
1720from ..utils import uniq
1821from .exceptions import BothReadOnly
2124from .exceptions import StorageEmpty
2225from .exceptions import SyncConflict
2326from .status import ItemMetadata
27+ from .status import SqliteStatus
2428from .status import SubStatus
2529
2630sync_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
9397async 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