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

Mypy fixes for synapse.handlers.federation #8422

Merged
merged 4 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions changelog.d/8422.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Typing fixes for `synapse.handlers.federation`.
4 changes: 3 additions & 1 deletion synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
Dict,
Iterable,
List,
Mapping,
Optional,
Sequence,
Tuple,
TypeVar,
Union,
)

from prometheus_client import Counter
Expand Down Expand Up @@ -501,7 +503,7 @@ async def make_membership_event(
user_id: str,
membership: str,
content: dict,
params: Dict[str, str],
params: Optional[Mapping[str, Union[str, Iterable[str]]]],
) -> Tuple[str, EventBase, RoomVersion]:
"""
Creates an m.room.member event, with context, without participating in the room.
Expand Down
13 changes: 9 additions & 4 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ def __init__(self, hs):
self._device_list_updater = hs.get_device_handler().device_list_updater
self._maybe_store_room_on_invite = self.store.maybe_store_room_on_invite

# When joining a room we need to queue any events for that room up
self.room_queues = {}
# When joining a room we need to queue any events for that room up.
# For each room, a list of (pdu, origin) tuples.
self.room_queues = {} # type: Dict[str, List[Tuple[EventBase, str]]]
self._room_pdu_linearizer = Linearizer("fed_room_pdu")

self.third_party_event_rules = hs.get_third_party_event_rules()
Expand Down Expand Up @@ -814,6 +815,9 @@ async def backfill(self, dest, room_id, limit, extremities):
dest, room_id, limit=limit, extremities=extremities
)

if not events:
return []

# ideally we'd sanity check the events here for excess prev_events etc,
# but it's hard to reject events at this point without completely
# breaking backfill in the same way that it is currently broken by
Expand Down Expand Up @@ -2164,10 +2168,10 @@ async def _check_for_soft_fail(
# given state at the event. This should correctly handle cases
# like bans, especially with state res v2.

state_sets = await self.state_store.get_state_groups(
state_sets_d = await self.state_store.get_state_groups(
event.room_id, extrem_ids
)
state_sets = list(state_sets.values())
state_sets = list(state_sets_d.values()) # type: List[Iterable[EventBase]]
state_sets.append(state)
current_states = await self.state_handler.resolve_events(
room_version, state_sets, event
Expand Down Expand Up @@ -2958,6 +2962,7 @@ async def persist_events_and_notify(
)
return result["max_stream_id"]
else:
assert self.storage.persistence
max_stream_token = await self.storage.persistence.persist_events(
event_and_contexts, backfilled=backfilled
)
Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/databases/state/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from synapse.storage.state import StateFilter
from synapse.storage.types import Cursor
from synapse.storage.util.sequence import build_sequence_generator
from synapse.types import StateMap
from synapse.types import MutableStateMap, StateMap
from synapse.util.caches.descriptors import cached
from synapse.util.caches.dictionary_cache import DictionaryCache

Expand Down Expand Up @@ -205,7 +205,7 @@ def _get_state_for_group_using_cache(self, cache, group, state_filter):

async def _get_state_for_groups(
self, groups: Iterable[int], state_filter: StateFilter = StateFilter.all()
) -> Dict[int, StateMap[str]]:
) -> Dict[int, MutableStateMap[str]]:
"""Gets the state at each of a list of state groups, optionally
filtering by type/state_key

Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/persist_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def __init__(self, hs, stores: Databases):

async def persist_events(
self,
events_and_contexts: List[Tuple[EventBase, EventContext]],
events_and_contexts: Iterable[Tuple[EventBase, EventContext]],
backfilled: bool = False,
) -> RoomStreamToken:
"""
Expand Down
6 changes: 3 additions & 3 deletions synapse/storage/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from synapse.api.constants import EventTypes
from synapse.events import EventBase
from synapse.types import StateMap
from synapse.types import MutableStateMap, StateMap

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -349,7 +349,7 @@ async def get_state_group_delta(self, state_group: int):

async def get_state_groups_ids(
self, _room_id: str, event_ids: Iterable[str]
) -> Dict[int, StateMap[str]]:
) -> Dict[int, MutableStateMap[str]]:
"""Get the event IDs of all the state for the state groups for the given events

Args:
Expand Down Expand Up @@ -532,7 +532,7 @@ async def get_state_ids_for_event(

def _get_state_for_groups(
self, groups: Iterable[int], state_filter: StateFilter = StateFilter.all()
) -> Awaitable[Dict[int, StateMap[str]]]:
) -> Awaitable[Dict[int, MutableStateMap[str]]]:
"""Gets the state at each of a list of state groups, optionally
filtering by type/state_key

Expand Down