From 67241232c52b58697c3cab3592adad1d990e71fb Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Fri, 1 Oct 2021 10:22:45 +0100 Subject: [PATCH] Fix annotations of types that feed into `get_json` and friends. --- synapse/federation/federation_client.py | 2 +- synapse/federation/transport/client.py | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/synapse/federation/federation_client.py b/synapse/federation/federation_client.py index 584836c04a..dae1c8a3fe 100644 --- a/synapse/federation/federation_client.py +++ b/synapse/federation/federation_client.py @@ -227,7 +227,7 @@ class FederationClient(FederationBase): ) async def backfill( - self, dest: str, room_id: str, limit: int, extremities: Iterable[str] + self, dest: str, room_id: str, limit: int, extremities: List[str] ) -> Optional[List[EventBase]]: """Requests some more historic PDUs for the given room from the given destination server. diff --git a/synapse/federation/transport/client.py b/synapse/federation/transport/client.py index 360eebdef7..d7033481c7 100644 --- a/synapse/federation/transport/client.py +++ b/synapse/federation/transport/client.py @@ -15,7 +15,7 @@ import logging import urllib -from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Tuple, Union +from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union import attr import ijson @@ -30,7 +30,11 @@ from synapse.api.urls import ( ) from synapse.events import EventBase, make_event_from_dict from synapse.federation.units import Transaction -from synapse.http.matrixfederationclient import ByteParser, MatrixFederationHttpClient +from synapse.http.matrixfederationclient import ( + ByteParser, + MatrixFederationHttpClient, + QueryArgs, +) from synapse.logging.utils import log_function from synapse.types import JsonDict @@ -104,7 +108,7 @@ class TransportLayerClient: @log_function async def backfill( - self, destination: str, room_id: str, event_tuples: Iterable[str], limit: int + self, destination: str, room_id: str, event_tuples: List[str], limit: int ) -> Optional[JsonDict]: """Requests `limit` previous PDUs in a given context before list of PDUs. @@ -132,7 +136,11 @@ class TransportLayerClient: path = _create_v1_path("/backfill/%s", room_id) - args = {"v": event_tuples, "limit": [str(limit)]} + # wide type annotation needed because Dict's value type parameter is invariant + args: Dict[str, Union[str, List[str]]] = { + "v": event_tuples, + "limit": [str(limit)], + } resp = await self.client.get_json( destination, path=path, args=args, try_trailing_slash_on_400=True @@ -213,7 +221,7 @@ class TransportLayerClient: room_id: str, user_id: str, membership: str, - params: Optional[Mapping[str, Union[str, Iterable[str]]]], + params: Optional[QueryArgs], ) -> JsonDict: """Asks a remote server to build and sign us a membership event