Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add missing type hints to synapse.appservice #11360

Merged
merged 11 commits into from
Dec 14, 2021
30 changes: 16 additions & 14 deletions synapse/appservice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
# limitations under the License.
import logging
import re
from typing import TYPE_CHECKING, Iterable, List, Match, Optional
from typing import TYPE_CHECKING, Iterable, List, Match, Optional, Pattern

from netaddr import IPSet

from synapse.api.constants import EventTypes
from synapse.events import EventBase
Expand Down Expand Up @@ -49,17 +51,17 @@ class ApplicationService:

def __init__(
self,
token,
hostname,
id,
sender,
url=None,
namespaces=None,
hs_token=None,
protocols=None,
rate_limited=True,
ip_range_whitelist=None,
supports_ephemeral=False,
token: str,
hostname: str,
id: str,
sender: str,
url: Optional[str] = None,
namespaces: Optional[JsonDict] = None,
hs_token: Optional[str] = None,
protocols: Iterable[str] = None,
rate_limited: bool = True,
ip_range_whitelist: Optional[IPSet] = None,
supports_ephemeral: bool = False,
):
self.token = token
self.url = (
Expand Down Expand Up @@ -284,7 +286,7 @@ def is_exclusive_alias(self, alias: str) -> bool:
def is_exclusive_room(self, room_id: str) -> bool:
return self._is_exclusive(ApplicationService.NS_ROOMS, room_id)

def get_exclusive_user_regexes(self):
def get_exclusive_user_regexes(self) -> List[Pattern]:
clokep marked this conversation as resolved.
Show resolved Hide resolved
"""Get the list of regexes used to determine if a user is exclusively
registered by the AS
"""
Expand Down Expand Up @@ -312,7 +314,7 @@ def get_groups_for_user(self, user_id: str) -> Iterable[str]:
def is_rate_limited(self) -> bool:
return self.rate_limited

def __str__(self):
def __str__(self) -> str:
# copy dictionary and redact token fields so they don't get logged
dict_copy = self.__dict__.copy()
dict_copy["token"] = "<redacted>"
Expand Down
3 changes: 1 addition & 2 deletions synapse/config/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ def _load_appservice(hostname, as_info, config_filename):
# protocols check
protocols = as_info.get("protocols")
if protocols:
# Because strings are lists in python
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(protocols, str) or not isinstance(protocols, list):
if not isinstance(protocols, list):
raise KeyError("Optional 'protocols' must be a list if present.")
for p in protocols:
if not isinstance(p, str):
Expand Down