13
13
import itertools
14
14
import logging
15
15
16
+ from vdirsyncer .storage .base import Storage
17
+ from vdirsyncer .vobject import Item
18
+
16
19
from ..exceptions import UserError
17
20
from ..utils import uniq
18
21
from .exceptions import BothReadOnly
21
24
from .exceptions import StorageEmpty
22
25
from .exceptions import SyncConflict
23
26
from .status import ItemMetadata
27
+ from .status import SqliteStatus
24
28
from .status import SubStatus
25
29
26
30
sync_logger = logging .getLogger (__name__ )
@@ -30,22 +34,22 @@ class _StorageInfo:
30
34
"""A wrapper class that holds prefetched items, the status and other
31
35
things."""
32
36
33
- def __init__ (self , storage , status ):
37
+ def __init__ (self , storage : Storage , status : SubStatus ):
34
38
self .storage = storage
35
39
self .status = status
36
- self ._item_cache = {}
40
+ self ._item_cache = {} # type: ignore[var-annotated]
37
41
38
- async def prepare_new_status (self ):
42
+ async def prepare_new_status (self ) -> bool :
39
43
storage_nonempty = False
40
44
prefetch = []
41
45
42
- def _store_props (ident , props ) :
46
+ def _store_props (ident : str , props : ItemMetadata ) -> None :
43
47
try :
44
48
self .status .insert_ident (ident , props )
45
49
except IdentAlreadyExists as e :
46
50
raise e .to_ident_conflict (self .storage )
47
51
48
- async for href , etag in self .storage .list ():
52
+ async for href , etag in self .storage .list (): # type: ignore[attr-defined]
49
53
storage_nonempty = True
50
54
ident , meta = self .status .get_by_href (href )
51
55
@@ -68,7 +72,7 @@ def _store_props(ident, props):
68
72
69
73
return storage_nonempty
70
74
71
- def is_changed (self , ident ) :
75
+ def is_changed (self , ident : str ) -> bool :
72
76
old_meta = self .status .get (ident )
73
77
if old_meta is None : # new item
74
78
return True
@@ -81,30 +85,28 @@ def is_changed(self, ident):
81
85
and (old_meta .hash is None or new_meta .hash != old_meta .hash )
82
86
)
83
87
84
- def set_item_cache (self , ident , item ):
88
+ def set_item_cache (self , ident , item ) -> None :
85
89
actual_hash = self .status .get_new (ident ).hash
86
90
assert actual_hash == item .hash
87
91
self ._item_cache [ident ] = item
88
92
89
- def get_item_cache (self , ident ) :
93
+ def get_item_cache (self , ident : str ) -> Item :
90
94
return self ._item_cache [ident ]
91
95
92
96
93
97
async def sync (
94
- storage_a ,
95
- storage_b ,
96
- status ,
98
+ storage_a : Storage ,
99
+ storage_b : Storage ,
100
+ status : SqliteStatus ,
97
101
conflict_resolution = None ,
98
102
force_delete = False ,
99
103
error_callback = None ,
100
104
partial_sync = "revert" ,
101
- ):
105
+ ) -> None :
102
106
"""Synchronizes two storages.
103
107
104
108
:param storage_a: The first storage
105
- :type storage_a: :class:`vdirsyncer.storage.base.Storage`
106
109
:param storage_b: The second storage
107
- :type storage_b: :class:`vdirsyncer.storage.base.Storage`
108
110
:param status: {ident: (href_a, etag_a, href_b, etag_b)}
109
111
metadata about the two storages for detection of changes. Will be
110
112
modified by the function and should be passed to it at the next sync.
0 commit comments