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

Fix up types and comments that refer to Deferreds. #7945

Merged
merged 3 commits into from
Jul 24, 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/7945.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update comments that refer to Deferreds for async functions.
2 changes: 1 addition & 1 deletion synapse/handlers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def export_user_data(self, user_id, writer):
writer (ExfiltrationWriter)

Returns:
defer.Deferred: Resolves when all data for a user has been written.
Resolves when all data for a user has been written.
The returned value is that returned by `writer.finished()`.
"""
# Get all rooms the user is in or has been in
Expand Down
24 changes: 13 additions & 11 deletions synapse/handlers/e2e_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
# limitations under the License.

import logging
from typing import Dict, List, Optional, Tuple

import attr
from canonicaljson import encode_canonical_json, json
from signedjson.key import decode_verify_key_bytes
from signedjson.key import VerifyKey, decode_verify_key_bytes
from signedjson.sign import SignatureVerifyException, verify_signed_json
from unpaddedbase64 import decode_base64

Expand Down Expand Up @@ -265,7 +266,9 @@ async def do_remote_query(destination):

return ret

async def get_cross_signing_keys_from_cache(self, query, from_user_id):
async def get_cross_signing_keys_from_cache(
self, query, from_user_id
) -> Dict[str, Dict[str, dict]]:
"""Get cross-signing keys for users from the database

Args:
Expand All @@ -277,8 +280,7 @@ async def get_cross_signing_keys_from_cache(self, query, from_user_id):
can see.

Returns:
defer.Deferred[dict[str, dict[str, dict]]]: map from
(master_keys|self_signing_keys|user_signing_keys) -> user_id -> key
A map from (master_keys|self_signing_keys|user_signing_keys) -> user_id -> key
"""
master_keys = {}
self_signing_keys = {}
Expand Down Expand Up @@ -312,16 +314,17 @@ async def get_cross_signing_keys_from_cache(self, query, from_user_id):
}

@trace
async def query_local_devices(self, query):
async def query_local_devices(
self, query: Dict[str, Optional[List[str]]]
) -> Dict[str, Dict[str, dict]]:
"""Get E2E device keys for local users

Args:
query (dict[string, list[string]|None): map from user_id to a list
query: map from user_id to a list
of devices to query (None for all devices)

Returns:
defer.Deferred: (resolves to dict[string, dict[string, dict]]):
map from user_id -> device_id -> device details
A map from user_id -> device_id -> device details
"""
set_tag("local_query", query)
local_query = []
Expand Down Expand Up @@ -1004,7 +1007,7 @@ async def _get_e2e_cross_signing_verify_key(

async def _retrieve_cross_signing_keys_for_remote_user(
self, user: UserID, desired_key_type: str,
):
) -> Tuple[Optional[dict], Optional[str], Optional[VerifyKey]]:
"""Queries cross-signing keys for a remote user and saves them to the database

Only the key specified by `key_type` will be returned, while all retrieved keys
Expand All @@ -1015,8 +1018,7 @@ async def _retrieve_cross_signing_keys_for_remote_user(
desired_key_type: The type of key to receive. One of "master", "self_signing"

Returns:
Deferred[Tuple[Optional[Dict], Optional[str], Optional[VerifyKey]]]: A tuple
of the retrieved key content, the key's ID and the matching VerifyKey.
A tuple of the retrieved key content, the key's ID and the matching VerifyKey.
If the key cannot be retrieved, all values in the tuple will instead be None.
"""
try:
Expand Down
8 changes: 5 additions & 3 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ async def do_invite_join(
# it's just a best-effort thing at this point. We do want to do
# them roughly in order, though, otherwise we'll end up making
# lots of requests for missing prev_events which we do actually
# have. Hence we fire off the deferred, but don't wait for it.
# have. Hence we fire off the background task, but don't wait for it.

run_in_background(self._handle_queued_pdus, room_queue)

Expand Down Expand Up @@ -2994,7 +2994,9 @@ async def user_joined_room(self, user: UserID, room_id: str) -> None:
else:
user_joined_room(self.distributor, user, room_id)

async def get_room_complexity(self, remote_room_hosts, room_id):
async def get_room_complexity(
self, remote_room_hosts: List[str], room_id: str
) -> Optional[dict]:
"""
Fetch the complexity of a remote room over federation.

Expand All @@ -3003,7 +3005,7 @@ async def get_room_complexity(self, remote_room_hosts, room_id):
room_id (str): The room ID to ask about.

Returns:
Deferred[dict] or Deferred[None]: Dict contains the complexity
Dict contains the complexity
metric versions, while None means we could not fetch the complexity.
"""

Expand Down
Loading