From 2880aef846197fe8b6226c8d4189f709f2402dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sun, 30 Dec 2018 23:37:28 +0100 Subject: [PATCH] xep_0384: Use Optional instead of Union[None, T] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- plugin.py | 4 ++-- storage.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugin.py b/plugin.py index f9713a0..de4a779 100644 --- a/plugin.py +++ b/plugin.py @@ -218,7 +218,7 @@ class XEP_0384(BasePlugin): iq = self._generate_bundle_iq() await iq.send() - async def _fetch_bundle(self, jid: str, device_id: int) -> Union[None, ExtendedPublicBundle]: + async def _fetch_bundle(self, jid: str, device_id: int) -> Optional[ExtendedPublicBundle]: node = '%s:%d' % (OMEMO_BUNDLES_NS, device_id) try: iq = await self.xmpp['xep_0060'].get_items(jid, node) @@ -357,7 +357,7 @@ class XEP_0384(BasePlugin): recipients = [jid.bare for jid in recipients] bundles = {} # type: Dict[str, Dict[int, ExtendedPublicBundle]] - old_errors = None # type: Union[None, List[Tuple[Exception, Any, Any]]] + old_errors = None # type: Optional[List[Tuple[Exception, Any, Any]]] while True: # Try to encrypt and resolve errors until there is no error at all # or if we hit the same set of errors. diff --git a/storage.py b/storage.py index 5907808..ccc6cb9 100644 --- a/storage.py +++ b/storage.py @@ -8,7 +8,7 @@ import os import copy import json -from typing import Any, Dict, List, Set, Union +from typing import Any, Dict, List, Optional, Set, Union import omemo @@ -17,7 +17,7 @@ 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, Union[str, int]]] + self.__own_data = None # type: Optional[Dict[str, Union[str, int]]] self.__sessions = {} # type: Dict[str, Dict[int, Any]] self.__devices = {} # type: Dict[str, Dict[str, Union[List[int], Dict[int, int]]]] self.__trust = {} # type: Dict[str, Dict[int, Dict[str, Any]]] @@ -92,7 +92,7 @@ class SyncFileStorage(omemo.Storage): filepath = os.path.join(self.storage_dir, 'sessions.json') os.remove(filepath) - def loadActiveDevices(self, _callback, bare_jid: str) -> Union[None, List[int]]: + def loadActiveDevices(self, _callback, bare_jid: str) -> Optional[List[int]]: if not self.__devices: try: filepath = os.path.join(self.storage_dir, 'devices.json') @@ -111,7 +111,7 @@ class SyncFileStorage(omemo.Storage): with open(filepath, 'w') as f: json.dump(self.__devices, f) - def loadInactiveDevices(self, _callback, bare_jid: str) -> Union[None, Dict[int, int]]: + def loadInactiveDevices(self, _callback, bare_jid: str) -> Optional[Dict[int, int]]: if not self.__devices: try: filepath = os.path.join(self.storage_dir, 'devices.json') @@ -138,7 +138,7 @@ class SyncFileStorage(omemo.Storage): with open(filepath, 'w') as f: json.dump(self.__trust, f) - def loadTrust(self, _callback, bare_jid: str, device_id: int) -> Union[None, Dict[str, Any]]: + def loadTrust(self, _callback, bare_jid: str, device_id: int) -> Optional[Dict[str, Any]]: if not self.__trust: try: filepath = os.path.join(self.storage_dir, 'trust.json')