Restore mypy support.
Fix errors with `make typecheck` and fix some typos.
This commit is contained in:
parent
368f5cfc3b
commit
a1abfdc3d6
4 changed files with 21 additions and 18 deletions
|
@ -26,7 +26,7 @@ import textwrap
|
||||||
# pylint: disable=redefined-builtin
|
# pylint: disable=redefined-builtin
|
||||||
from builtins import str
|
from builtins import str
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from typing import List
|
from typing import Dict, List, Optional, Union
|
||||||
|
|
||||||
import webcolors
|
import webcolors
|
||||||
from pygments import highlight
|
from pygments import highlight
|
||||||
|
@ -476,7 +476,6 @@ class Formatted(object):
|
||||||
return "".join(strings).strip()
|
return "".join(strings).strip()
|
||||||
|
|
||||||
|
|
||||||
# TODO this should be a typed dict.
|
|
||||||
DEFAULT_ATTRIBUTES = {
|
DEFAULT_ATTRIBUTES = {
|
||||||
"bold": False,
|
"bold": False,
|
||||||
"italic": False,
|
"italic": False,
|
||||||
|
@ -487,7 +486,7 @@ DEFAULT_ATTRIBUTES = {
|
||||||
"code": None,
|
"code": None,
|
||||||
"fgcolor": None,
|
"fgcolor": None,
|
||||||
"bgcolor": None,
|
"bgcolor": None,
|
||||||
}
|
} # type: Dict[str, Union[bool, Optional[str]]]
|
||||||
|
|
||||||
|
|
||||||
class MatrixHtmlParser(HTMLParser):
|
class MatrixHtmlParser(HTMLParser):
|
||||||
|
|
|
@ -36,7 +36,7 @@ from .uploads import UploadsBuffer, Upload
|
||||||
try:
|
try:
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse # type: ignore
|
||||||
|
|
||||||
|
|
||||||
class ParseError(Exception):
|
class ParseError(Exception):
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from typing import Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
from logbook import Logger
|
from logbook import Logger
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ except ImportError:
|
||||||
W = weechat
|
W = weechat
|
||||||
|
|
||||||
SERVERS = dict() # type: Dict[str, MatrixServer]
|
SERVERS = dict() # type: Dict[str, MatrixServer]
|
||||||
CONFIG = None # type: Optional[MatrixConfig]
|
CONFIG = None # type: Any
|
||||||
ENCRYPTION = True # type: bool
|
ENCRYPTION = True # type: bool
|
||||||
SCRIPT_NAME = "matrix" # type: str
|
SCRIPT_NAME = "matrix" # type: str
|
||||||
TYPING_NOTICE_TIMEOUT = 4000 # 4 seconds typing notice lifetime
|
TYPING_NOTICE_TIMEOUT = 4000 # 4 seconds typing notice lifetime
|
||||||
|
|
|
@ -32,7 +32,8 @@ from typing import (
|
||||||
List,
|
List,
|
||||||
NamedTuple,
|
NamedTuple,
|
||||||
DefaultDict,
|
DefaultDict,
|
||||||
Union
|
Type,
|
||||||
|
Union,
|
||||||
)
|
)
|
||||||
|
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
@ -73,6 +74,7 @@ from nio import (
|
||||||
KeyVerificationKey,
|
KeyVerificationKey,
|
||||||
KeyVerificationMac,
|
KeyVerificationMac,
|
||||||
KeyVerificationEvent,
|
KeyVerificationEvent,
|
||||||
|
ToDeviceMessage,
|
||||||
ToDeviceResponse,
|
ToDeviceResponse,
|
||||||
ToDeviceError
|
ToDeviceError
|
||||||
)
|
)
|
||||||
|
@ -90,7 +92,7 @@ from .colors import Formatted, FormattedString, DEFAULT_ATTRIBUTES
|
||||||
try:
|
try:
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse # type: ignore
|
||||||
|
|
||||||
try:
|
try:
|
||||||
FileNotFoundError # type: ignore
|
FileNotFoundError # type: ignore
|
||||||
|
@ -98,8 +100,8 @@ except NameError:
|
||||||
FileNotFoundError = IOError
|
FileNotFoundError = IOError
|
||||||
|
|
||||||
|
|
||||||
EncrytpionQueueItem = NamedTuple(
|
EncryptionQueueItem = NamedTuple(
|
||||||
"EncrytpionQueueItem",
|
"EncryptionQueueItem",
|
||||||
[
|
[
|
||||||
("message_type", str),
|
("message_type", str),
|
||||||
("message", Union[Formatted, Upload]),
|
("message", Union[Formatted, Upload]),
|
||||||
|
@ -307,7 +309,7 @@ class MatrixServer(object):
|
||||||
|
|
||||||
self.address = None
|
self.address = None
|
||||||
self.homeserver = None
|
self.homeserver = None
|
||||||
self.client = None
|
self.client = None # type: Optional[HttpClient]
|
||||||
self.access_token = None # type: Optional[str]
|
self.access_token = None # type: Optional[str]
|
||||||
self.next_batch = None # type: Optional[str]
|
self.next_batch = None # type: Optional[str]
|
||||||
self.transaction_id = 0 # type: int
|
self.transaction_id = 0 # type: int
|
||||||
|
@ -323,7 +325,7 @@ class MatrixServer(object):
|
||||||
self.device_deletion_queue = dict() # type: Dict[str, str]
|
self.device_deletion_queue = dict() # type: Dict[str, str]
|
||||||
|
|
||||||
self.encryption_queue = defaultdict(deque) \
|
self.encryption_queue = defaultdict(deque) \
|
||||||
# type: DefaultDict[str, Deque[EncrytpionQueueItem]]
|
# type: DefaultDict[str, Deque[EncryptionQueueItem]]
|
||||||
self.backlog_queue = dict() # type: Dict[str, str]
|
self.backlog_queue = dict() # type: Dict[str, str]
|
||||||
|
|
||||||
self.user_gc_time = time.time() # type: float
|
self.user_gc_time = time.time() # type: float
|
||||||
|
@ -337,8 +339,8 @@ class MatrixServer(object):
|
||||||
self.keys_queried = False # type: bool
|
self.keys_queried = False # type: bool
|
||||||
self.keys_claimed = defaultdict(bool) # type: Dict[str, bool]
|
self.keys_claimed = defaultdict(bool) # type: Dict[str, bool]
|
||||||
self.group_session_shared = defaultdict(bool) # type: Dict[str, bool]
|
self.group_session_shared = defaultdict(bool) # type: Dict[str, bool]
|
||||||
self.ignore_while_sharing = defaultdict(bool)
|
self.ignore_while_sharing = defaultdict(bool) # type: Dict[str, bool]
|
||||||
self.to_device_sent = []
|
self.to_device_sent = [] # type: List[ToDeviceMessage]
|
||||||
|
|
||||||
# Try to load the device id, the device id is loaded every time the
|
# Try to load the device id, the device id is loaded every time the
|
||||||
# user changes but some login flows don't use a user so try to load the
|
# user changes but some login flows don't use a user so try to load the
|
||||||
|
@ -833,7 +835,8 @@ class MatrixServer(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
def login(self, token=None):
|
def login(self, token=None):
|
||||||
# type: () -> None
|
# type: (...) -> None
|
||||||
|
assert self.client is not None
|
||||||
if self.client.logged_in:
|
if self.client.logged_in:
|
||||||
msg = (
|
msg = (
|
||||||
"{prefix}{script_name}: Already logged in, " "syncing..."
|
"{prefix}{script_name}: Already logged in, " "syncing..."
|
||||||
|
@ -1034,7 +1037,7 @@ class MatrixServer(object):
|
||||||
try:
|
try:
|
||||||
uuid = self.room_send_event(upload.room_id, content)
|
uuid = self.room_send_event(upload.room_id, content)
|
||||||
except (EncryptionError, GroupEncryptionError):
|
except (EncryptionError, GroupEncryptionError):
|
||||||
message = EncrytpionQueueItem(upload.msgtype, upload)
|
message = EncryptionQueueItem(upload.msgtype, upload)
|
||||||
self.encryption_queue[upload.room_id].append(message)
|
self.encryption_queue[upload.room_id].append(message)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -1127,12 +1130,12 @@ class MatrixServer(object):
|
||||||
ignore_unverified_devices=ignore_unverified_devices
|
ignore_unverified_devices=ignore_unverified_devices
|
||||||
)
|
)
|
||||||
except (EncryptionError, GroupEncryptionError):
|
except (EncryptionError, GroupEncryptionError):
|
||||||
message = EncrytpionQueueItem(msgtype, formatted)
|
message = EncryptionQueueItem(msgtype, formatted)
|
||||||
self.encryption_queue[room.room_id].append(message)
|
self.encryption_queue[room.room_id].append(message)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if msgtype == "m.emote":
|
if msgtype == "m.emote":
|
||||||
message_class = OwnAction
|
message_class = OwnAction # type: Type
|
||||||
else:
|
else:
|
||||||
message_class = OwnMessage
|
message_class = OwnMessage
|
||||||
|
|
||||||
|
@ -1715,6 +1718,7 @@ class MatrixServer(object):
|
||||||
]:
|
]:
|
||||||
ret = self.room_send_upload(item.message)
|
ret = self.room_send_upload(item.message)
|
||||||
else:
|
else:
|
||||||
|
assert isinstance(item.message, Formatted)
|
||||||
ret = self.room_send_message(
|
ret = self.room_send_message(
|
||||||
room_buffer,
|
room_buffer,
|
||||||
item.message,
|
item.message,
|
||||||
|
|
Loading…
Add table
Reference in a new issue