Use StrCollection in place of Collection[str] in (most) handlers code. (#14922)

Due to the increased safety of StrCollection over Collection[str]
and Sequence[str].
This commit is contained in:
Patrick Cloke 2023-01-26 12:31:58 -05:00 committed by GitHub
parent dc901a885f
commit ba79fb4a61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 43 additions and 58 deletions

View file

@ -20,17 +20,7 @@ import itertools
import logging
from enum import Enum
from http import HTTPStatus
from typing import (
TYPE_CHECKING,
Collection,
Dict,
Iterable,
List,
Optional,
Set,
Tuple,
Union,
)
from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Set, Tuple, Union
import attr
from prometheus_client import Histogram
@ -70,7 +60,7 @@ from synapse.replication.http.federation import (
)
from synapse.storage.databases.main.events import PartialStateConflictError
from synapse.storage.databases.main.events_worker import EventRedactBehaviour
from synapse.types import JsonDict, get_domain_from_id
from synapse.types import JsonDict, StrCollection, get_domain_from_id
from synapse.types.state import StateFilter
from synapse.util.async_helpers import Linearizer
from synapse.util.retryutils import NotRetryingDestination
@ -179,7 +169,7 @@ class FederationHandler:
# A dictionary mapping room IDs to (initial destination, other destinations)
# tuples.
self._partial_state_syncs_maybe_needing_restart: Dict[
str, Tuple[Optional[str], Collection[str]]
str, Tuple[Optional[str], StrCollection]
] = {}
# A lock guarding the partial state flag for rooms.
# When the lock is held for a given room, no other concurrent code may
@ -437,7 +427,7 @@ class FederationHandler:
)
)
async def try_backfill(domains: Collection[str]) -> bool:
async def try_backfill(domains: StrCollection) -> bool:
# TODO: Should we try multiple of these at a time?
# Number of contacted remote homeservers that have denied our backfill
@ -1730,7 +1720,7 @@ class FederationHandler:
def _start_partial_state_room_sync(
self,
initial_destination: Optional[str],
other_destinations: Collection[str],
other_destinations: StrCollection,
room_id: str,
) -> None:
"""Starts the background process to resync the state of a partial state room,
@ -1812,7 +1802,7 @@ class FederationHandler:
async def _sync_partial_state_room(
self,
initial_destination: Optional[str],
other_destinations: Collection[str],
other_destinations: StrCollection,
room_id: str,
) -> None:
"""Background process to resync the state of a partial-state room
@ -1949,9 +1939,9 @@ class FederationHandler:
def _prioritise_destinations_for_partial_state_resync(
initial_destination: Optional[str],
other_destinations: Collection[str],
other_destinations: StrCollection,
room_id: str,
) -> Collection[str]:
) -> StrCollection:
"""Work out the order in which we should ask servers to resync events.
If an `initial_destination` is given, it takes top priority. Otherwise