xep_0384: some more mypy checks

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2018-11-19 21:40:29 +01:00
parent 252b789f85
commit 41919a7a5e

View file

@ -4,21 +4,22 @@
Shamelessly inspired from Syndace's python-omemo examples.
"""
import omemo
import os
import copy
import json
from typing import Any, Dict, Set, Union
from typing import Any, Dict, List, Set, Union
import omemo
class SyncFileStorage(omemo.Storage):
def __init__(self, storage_dir: str) -> None:
self.storage_dir = storage_dir
self.__state = None
self.__own_data = None # type: Union[None, Dict[str, str]]
self.__own_data = None # type: Union[None, Dict[str, Union[str, int]]]
self.__sessions = {} # type: Dict[str, Dict[int, Any]]
self.__devices = {} # type: Dict[str, Dict[str, Set[int]]]
self.__devices = {} # type: Dict[str, Dict[str, List[int]]]
def dump(self):
return copy.deepcopy({
@ -72,8 +73,8 @@ class SyncFileStorage(omemo.Storage):
self.__sessions[bare_jid] = self.__sessions.get(bare_jid, {})
self.__sessions[bare_jid][device_id] = session
def loadActiveDevices(self, _callback, bare_jid: str) -> Union[None, Set[int]]:
if self.__devices is None:
def loadActiveDevices(self, _callback, bare_jid: str) -> Union[None, List[int]]:
if not self.__devices:
try:
filepath = os.path.join(self.storage_dir, 'devices.json')
with open(filepath, 'r') as f:
@ -91,8 +92,8 @@ class SyncFileStorage(omemo.Storage):
with open(filepath, 'w') as f:
json.dump(self.__devices, f)
def loadInactiveDevices(self, _callback, bare_jid: str) -> Union[None, Set[int]]:
if self.__devices is None:
def loadInactiveDevices(self, _callback, bare_jid: str) -> Union[None, List[int]]:
if not self.__devices:
try:
filepath = os.path.join(self.storage_dir, 'devices.json')
with open(filepath, 'r') as f: