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

Fix typing for SyncHandler #8237

Merged
merged 2 commits into from
Sep 3, 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/8237.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix type hints in `SyncHandler`.
12 changes: 7 additions & 5 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import itertools
import logging
from typing import Any, Dict, FrozenSet, List, Optional, Set, Tuple
from typing import TYPE_CHECKING, Any, Dict, FrozenSet, List, Optional, Set, Tuple

import attr
from prometheus_client import Counter
Expand Down Expand Up @@ -44,6 +44,9 @@
from synapse.util.metrics import Measure, measure_func
from synapse.visibility import filter_events_for_client

if TYPE_CHECKING:
from synapse.server import HomeServer

logger = logging.getLogger(__name__)

# Debug logger for https://github.com/matrix-org/synapse/issues/4422
Expand Down Expand Up @@ -244,7 +247,7 @@ def __nonzero__(self) -> bool:


class SyncHandler(object):
def __init__(self, hs):
def __init__(self, hs: "HomeServer"):
self.hs_config = hs.config
self.store = hs.get_datastore()
self.notifier = hs.get_notifier()
Expand Down Expand Up @@ -717,9 +720,8 @@ async def compute_summary(
]

missing_hero_state = await self.store.get_events(missing_hero_event_ids)
missing_hero_state = missing_hero_state.values()

for s in missing_hero_state:
for s in missing_hero_state.values():
cache.set(s.state_key, s.event_id)
state[(EventTypes.Member, s.state_key)] = s

Expand Down Expand Up @@ -1771,7 +1773,7 @@ async def _generate_room_entry(
ignored_users: Set[str],
room_builder: "RoomSyncResultBuilder",
ephemeral: List[JsonDict],
tags: Optional[List[JsonDict]],
tags: Optional[Dict[str, Dict[str, Any]]],
account_data: Dict[str, JsonDict],
always_include: bool = False,
):
Expand Down
6 changes: 3 additions & 3 deletions synapse/storage/databases/main/roommember.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ async def get_invite_for_local_user_in_room(
return None

async def get_rooms_for_local_user_where_membership_is(
self, user_id: str, membership_list: List[str]
) -> Optional[List[RoomsForUser]]:
self, user_id: str, membership_list: Collection[str]
) -> List[RoomsForUser]:
"""Get all the rooms for this *local* user where the membership for this user
matches one in the membership list.

Expand All @@ -314,7 +314,7 @@ async def get_rooms_for_local_user_where_membership_is(
The RoomsForUser that the user matches the membership types.
"""
if not membership_list:
return None
return []
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing passes in an empty list so this should be a no-op change. Doing this allows us to avoid unwrapping the optional, plus I think makes semantic sense.


rooms = await self.db_pool.runInteraction(
"get_rooms_for_local_user_where_membership_is",
Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/databases/main/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def get_tags_for_user(self, user_id: str) -> Dict[str, Dict[str, JsonDict]
"room_tags", {"user_id": user_id}, ["room_id", "tag", "content"]
)

tags_by_room = {}
tags_by_room = {} # type: Dict[str, Dict[str, JsonDict]]
for row in rows:
room_tags = tags_by_room.setdefault(row["room_id"], {})
room_tags[row["tag"]] = db_to_json(row["content"])
Expand Down Expand Up @@ -123,7 +123,7 @@ def get_tag_content(txn, tag_ids):

async def get_updated_tags(
self, user_id: str, stream_id: int
) -> Dict[str, List[str]]:
) -> Dict[str, Dict[str, JsonDict]]:
"""Get all the tags for the rooms where the tags have changed since the
given version

Expand Down