mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-29 15:39:00 +03:00
Mypy fixes for synapse.handlers.federation
(#8422)
For some reason, an apparently unrelated PR upset mypy about this module. Here are a number of little fixes.
This commit is contained in:
parent
12f0d18611
commit
2649d545a5
6 changed files with 19 additions and 11 deletions
1
changelog.d/8422.misc
Normal file
1
changelog.d/8422.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Typing fixes for `synapse.handlers.federation`.
|
|
@ -24,10 +24,12 @@ from typing import (
|
||||||
Dict,
|
Dict,
|
||||||
Iterable,
|
Iterable,
|
||||||
List,
|
List,
|
||||||
|
Mapping,
|
||||||
Optional,
|
Optional,
|
||||||
Sequence,
|
Sequence,
|
||||||
Tuple,
|
Tuple,
|
||||||
TypeVar,
|
TypeVar,
|
||||||
|
Union,
|
||||||
)
|
)
|
||||||
|
|
||||||
from prometheus_client import Counter
|
from prometheus_client import Counter
|
||||||
|
@ -501,7 +503,7 @@ class FederationClient(FederationBase):
|
||||||
user_id: str,
|
user_id: str,
|
||||||
membership: str,
|
membership: str,
|
||||||
content: dict,
|
content: dict,
|
||||||
params: Dict[str, str],
|
params: Optional[Mapping[str, Union[str, Iterable[str]]]],
|
||||||
) -> Tuple[str, EventBase, RoomVersion]:
|
) -> Tuple[str, EventBase, RoomVersion]:
|
||||||
"""
|
"""
|
||||||
Creates an m.room.member event, with context, without participating in the room.
|
Creates an m.room.member event, with context, without participating in the room.
|
||||||
|
|
|
@ -155,8 +155,9 @@ class FederationHandler(BaseHandler):
|
||||||
self._device_list_updater = hs.get_device_handler().device_list_updater
|
self._device_list_updater = hs.get_device_handler().device_list_updater
|
||||||
self._maybe_store_room_on_invite = self.store.maybe_store_room_on_invite
|
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
|
# When joining a room we need to queue any events for that room up.
|
||||||
self.room_queues = {}
|
# 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._room_pdu_linearizer = Linearizer("fed_room_pdu")
|
||||||
|
|
||||||
self.third_party_event_rules = hs.get_third_party_event_rules()
|
self.third_party_event_rules = hs.get_third_party_event_rules()
|
||||||
|
@ -814,6 +815,9 @@ class FederationHandler(BaseHandler):
|
||||||
dest, room_id, limit=limit, extremities=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,
|
# 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
|
# but it's hard to reject events at this point without completely
|
||||||
# breaking backfill in the same way that it is currently broken by
|
# breaking backfill in the same way that it is currently broken by
|
||||||
|
@ -2164,10 +2168,10 @@ class FederationHandler(BaseHandler):
|
||||||
# given state at the event. This should correctly handle cases
|
# given state at the event. This should correctly handle cases
|
||||||
# like bans, especially with state res v2.
|
# 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
|
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)
|
state_sets.append(state)
|
||||||
current_states = await self.state_handler.resolve_events(
|
current_states = await self.state_handler.resolve_events(
|
||||||
room_version, state_sets, event
|
room_version, state_sets, event
|
||||||
|
@ -2958,6 +2962,7 @@ class FederationHandler(BaseHandler):
|
||||||
)
|
)
|
||||||
return result["max_stream_id"]
|
return result["max_stream_id"]
|
||||||
else:
|
else:
|
||||||
|
assert self.storage.persistence
|
||||||
max_stream_token = await self.storage.persistence.persist_events(
|
max_stream_token = await self.storage.persistence.persist_events(
|
||||||
event_and_contexts, backfilled=backfilled
|
event_and_contexts, backfilled=backfilled
|
||||||
)
|
)
|
||||||
|
|
|
@ -24,7 +24,7 @@ from synapse.storage.databases.state.bg_updates import StateBackgroundUpdateStor
|
||||||
from synapse.storage.state import StateFilter
|
from synapse.storage.state import StateFilter
|
||||||
from synapse.storage.types import Cursor
|
from synapse.storage.types import Cursor
|
||||||
from synapse.storage.util.sequence import build_sequence_generator
|
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.descriptors import cached
|
||||||
from synapse.util.caches.dictionary_cache import DictionaryCache
|
from synapse.util.caches.dictionary_cache import DictionaryCache
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ class StateGroupDataStore(StateBackgroundUpdateStore, SQLBaseStore):
|
||||||
|
|
||||||
async def _get_state_for_groups(
|
async def _get_state_for_groups(
|
||||||
self, groups: Iterable[int], state_filter: StateFilter = StateFilter.all()
|
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
|
"""Gets the state at each of a list of state groups, optionally
|
||||||
filtering by type/state_key
|
filtering by type/state_key
|
||||||
|
|
||||||
|
|
|
@ -197,7 +197,7 @@ class EventsPersistenceStorage:
|
||||||
|
|
||||||
async def persist_events(
|
async def persist_events(
|
||||||
self,
|
self,
|
||||||
events_and_contexts: List[Tuple[EventBase, EventContext]],
|
events_and_contexts: Iterable[Tuple[EventBase, EventContext]],
|
||||||
backfilled: bool = False,
|
backfilled: bool = False,
|
||||||
) -> RoomStreamToken:
|
) -> RoomStreamToken:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -20,7 +20,7 @@ import attr
|
||||||
|
|
||||||
from synapse.api.constants import EventTypes
|
from synapse.api.constants import EventTypes
|
||||||
from synapse.events import EventBase
|
from synapse.events import EventBase
|
||||||
from synapse.types import StateMap
|
from synapse.types import MutableStateMap, StateMap
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -349,7 +349,7 @@ class StateGroupStorage:
|
||||||
|
|
||||||
async def get_state_groups_ids(
|
async def get_state_groups_ids(
|
||||||
self, _room_id: str, event_ids: Iterable[str]
|
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
|
"""Get the event IDs of all the state for the state groups for the given events
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -532,7 +532,7 @@ class StateGroupStorage:
|
||||||
|
|
||||||
def _get_state_for_groups(
|
def _get_state_for_groups(
|
||||||
self, groups: Iterable[int], state_filter: StateFilter = StateFilter.all()
|
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
|
"""Gets the state at each of a list of state groups, optionally
|
||||||
filtering by type/state_key
|
filtering by type/state_key
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue