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

Add type hints to synapse.handlers.room #8090

Merged
merged 5 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import math
import string
from collections import OrderedDict
from typing import Awaitable, Optional, Tuple
from typing import TYPE_CHECKING, Any, Awaitable, Dict, Optional, Tuple

from synapse.api.constants import (
EventTypes,
Expand Down Expand Up @@ -53,6 +53,9 @@

from ._base import BaseHandler

if TYPE_CHECKING:
from synapse.server import HomeServer

logger = logging.getLogger(__name__)

id_server_scheme = "https://"
Expand All @@ -61,7 +64,7 @@


class RoomCreationHandler(BaseHandler):
def __init__(self, hs):
def __init__(self, hs: "HomeServer"):
super(RoomCreationHandler, self).__init__(hs)

self.spam_checker = hs.get_spam_checker()
Expand Down Expand Up @@ -92,7 +95,7 @@ def __init__(self, hs):
"guest_can_join": False,
"power_level_content_override": {},
},
}
} # type: Dict[str, Dict[str, Any]]

# Modify presets to selectively enable encryption by default per homeserver config
for preset_name, preset_config in self._presets_dict.items():
Expand Down Expand Up @@ -215,6 +218,9 @@ async def _upgrade_room(

old_room_state = await tombstone_context.get_current_state_ids()

# We know the tombstone event isn't an outlier so it has current state.
assert old_room_state is not None
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved

# update any aliases
await self._move_aliases_to_new_room(
requester, old_room_id, new_room_id, old_room_state
Expand Down Expand Up @@ -601,6 +607,7 @@ async def create_room(
Codes.UNSUPPORTED_ROOM_VERSION,
)

room_alias = None
if "room_alias_name" in config:
for wchar in string.whitespace:
if wchar in config["room_alias_name"]:
Expand All @@ -611,8 +618,6 @@ async def create_room(

if mapping:
raise SynapseError(400, "Room alias already taken", Codes.ROOM_IN_USE)
else:
room_alias = None

invite_list = config.get("invite", [])
for i in invite_list:
Expand Down Expand Up @@ -787,6 +792,10 @@ async def _send_events_for_new_room(
The stream_id of the last event persisted.
"""

creator_id = creator.user.to_string()

event_keys = {"room_id": room_id, "sender": creator_id, "state_key": ""}

def create(etype, content, **kwargs):
e = {"type": etype, "content": content}

Expand All @@ -808,10 +817,6 @@ async def send(etype, content, **kwargs) -> int:

config = self._presets_dict[preset_config]

creator_id = creator.user.to_string()

event_keys = {"room_id": room_id, "sender": creator_id, "state_key": ""}

creation_content.update({"creator": creator_id})
await send(etype=EventTypes.Create, content=creation_content)

Expand Down Expand Up @@ -852,7 +857,7 @@ async def send(etype, content, **kwargs) -> int:
"kick": 50,
"redact": 50,
"invite": 50,
}
} # type: Dict[str, Any]
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved

if config["original_invitees_have_ops"]:
for invitee in invite_list:
Expand Down Expand Up @@ -906,7 +911,7 @@ async def send(etype, content, **kwargs) -> int:
return last_sent_stream_id

async def _generate_room_id(
self, creator_id: str, is_public: str, room_version: RoomVersion,
self, creator_id: str, is_public: bool, room_version: RoomVersion,
):
# autogen room IDs and try to create it. We may clash, so just
# try a few times till one goes through, giving up eventually.
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ commands=
skip_install = True
deps =
{[base]deps}
mypy==0.750
mypy==0.782
mypy-zope
env =
MYPYPATH = stubs/
Expand All @@ -190,6 +190,7 @@ commands = mypy \
synapse/handlers/message.py \
synapse/handlers/oidc_handler.py \
synapse/handlers/presence.py \
synapse/handlers/room.py \
synapse/handlers/room_member.py \
synapse/handlers/room_member_worker.py \
synapse/handlers/saml_handler.py \
Expand Down