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

Re-type hint some collections in /sync code as read-only #13754

Merged
merged 2 commits into from
Sep 8, 2022
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
1 change: 1 addition & 0 deletions changelog.d/13754.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Re-type hint some collections as read-only.
19 changes: 9 additions & 10 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import logging
from typing import (
TYPE_CHECKING,
AbstractSet,
Any,
Collection,
Dict,
Expand Down Expand Up @@ -1413,10 +1414,10 @@ async def generate_sync_result(
async def _generate_sync_entry_for_device_list(
self,
sync_result_builder: "SyncResultBuilder",
newly_joined_rooms: Set[str],
newly_joined_or_invited_or_knocked_users: Set[str],
newly_left_rooms: Set[str],
newly_left_users: Set[str],
newly_joined_rooms: AbstractSet[str],
clokep marked this conversation as resolved.
Show resolved Hide resolved
newly_joined_or_invited_or_knocked_users: AbstractSet[str],
newly_left_rooms: AbstractSet[str],
newly_left_users: AbstractSet[str],
) -> DeviceListUpdates:
"""Generate the DeviceListUpdates section of sync

Expand All @@ -1434,8 +1435,6 @@ async def _generate_sync_entry_for_device_list(
user_id = sync_result_builder.sync_config.user.to_string()
since_token = sync_result_builder.since_token

# We're going to mutate these fields, so lets copy them rather than
# assume they won't get used later.
clokep marked this conversation as resolved.
Show resolved Hide resolved
newly_joined_or_invited_or_knocked_users = set(
newly_joined_or_invited_or_knocked_users
)
Expand Down Expand Up @@ -1635,8 +1634,8 @@ async def _generate_sync_entry_for_account_data(
async def _generate_sync_entry_for_presence(
self,
sync_result_builder: "SyncResultBuilder",
newly_joined_rooms: Set[str],
newly_joined_or_invited_users: Set[str],
newly_joined_rooms: AbstractSet[str],
newly_joined_or_invited_users: AbstractSet[str],
) -> None:
"""Generates the presence portion of the sync response. Populates the
`sync_result_builder` with the result.
Expand Down Expand Up @@ -1694,7 +1693,7 @@ async def _generate_sync_entry_for_rooms(
self,
sync_result_builder: "SyncResultBuilder",
account_data_by_room: Dict[str, Dict[str, JsonDict]],
) -> Tuple[Set[str], Set[str], Set[str], Set[str]]:
) -> Tuple[AbstractSet[str], AbstractSet[str], AbstractSet[str], AbstractSet[str]]:
"""Generates the rooms portion of the sync response. Populates the
`sync_result_builder` with the result.

Expand Down Expand Up @@ -2534,7 +2533,7 @@ class SyncResultBuilder:
archived: List[ArchivedSyncResult] = attr.Factory(list)
to_device: List[JsonDict] = attr.Factory(list)

def calculate_user_changes(self) -> Tuple[Set[str], Set[str]]:
def calculate_user_changes(self) -> Tuple[AbstractSet[str], AbstractSet[str]]:
"""Work out which other users have joined or left rooms we are joined to.

This data only is only useful for an incremental sync.
Expand Down