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

This commit is contained in:
Patrick Cloke 2020-07-24 10:53:25 -04:00 committed by GitHub
parent 53f7b49f5b
commit e739b20588
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 174 additions and 157 deletions

1
changelog.d/7945.misc Normal file
View file

@ -0,0 +1 @@
Update comments that refer to Deferreds for async functions.

View file

@ -72,7 +72,7 @@ class AdminHandler(BaseHandler):
writer (ExfiltrationWriter) writer (ExfiltrationWriter)
Returns: 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()`. The returned value is that returned by `writer.finished()`.
""" """
# Get all rooms the user is in or has been in # Get all rooms the user is in or has been in

View file

@ -16,10 +16,11 @@
# limitations under the License. # limitations under the License.
import logging import logging
from typing import Dict, List, Optional, Tuple
import attr import attr
from canonicaljson import encode_canonical_json, json 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 signedjson.sign import SignatureVerifyException, verify_signed_json
from unpaddedbase64 import decode_base64 from unpaddedbase64 import decode_base64
@ -265,7 +266,9 @@ class E2eKeysHandler(object):
return ret 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 """Get cross-signing keys for users from the database
Args: Args:
@ -277,8 +280,7 @@ class E2eKeysHandler(object):
can see. can see.
Returns: Returns:
defer.Deferred[dict[str, dict[str, dict]]]: map from A map from (master_keys|self_signing_keys|user_signing_keys) -> user_id -> key
(master_keys|self_signing_keys|user_signing_keys) -> user_id -> key
""" """
master_keys = {} master_keys = {}
self_signing_keys = {} self_signing_keys = {}
@ -312,16 +314,17 @@ class E2eKeysHandler(object):
} }
@trace @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 """Get E2E device keys for local users
Args: 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) of devices to query (None for all devices)
Returns: Returns:
defer.Deferred: (resolves to dict[string, dict[string, dict]]): A map from user_id -> device_id -> device details
map from user_id -> device_id -> device details
""" """
set_tag("local_query", query) set_tag("local_query", query)
local_query = [] local_query = []
@ -1004,7 +1007,7 @@ class E2eKeysHandler(object):
async def _retrieve_cross_signing_keys_for_remote_user( async def _retrieve_cross_signing_keys_for_remote_user(
self, user: UserID, desired_key_type: str, 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 """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 Only the key specified by `key_type` will be returned, while all retrieved keys
@ -1015,8 +1018,7 @@ class E2eKeysHandler(object):
desired_key_type: The type of key to receive. One of "master", "self_signing" desired_key_type: The type of key to receive. One of "master", "self_signing"
Returns: Returns:
Deferred[Tuple[Optional[Dict], Optional[str], Optional[VerifyKey]]]: A tuple A tuple of the retrieved key content, the key's ID and the matching VerifyKey.
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. If the key cannot be retrieved, all values in the tuple will instead be None.
""" """
try: try:

View file

@ -1394,7 +1394,7 @@ class FederationHandler(BaseHandler):
# it's just a best-effort thing at this point. We do want to do # 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 # them roughly in order, though, otherwise we'll end up making
# lots of requests for missing prev_events which we do actually # 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) run_in_background(self._handle_queued_pdus, room_queue)
@ -2994,7 +2994,9 @@ class FederationHandler(BaseHandler):
else: else:
user_joined_room(self.distributor, user, room_id) 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. Fetch the complexity of a remote room over federation.
@ -3003,7 +3005,7 @@ class FederationHandler(BaseHandler):
room_id (str): The room ID to ask about. room_id (str): The room ID to ask about.
Returns: 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. metric versions, while None means we could not fetch the complexity.
""" """

View file

@ -19,6 +19,7 @@
import logging import logging
import urllib.parse import urllib.parse
from typing import Awaitable, Callable, Dict, List, Optional, Tuple
from canonicaljson import json from canonicaljson import json
from signedjson.key import decode_verify_key_bytes from signedjson.key import decode_verify_key_bytes
@ -36,6 +37,7 @@ from synapse.api.errors import (
) )
from synapse.config.emailconfig import ThreepidBehaviour from synapse.config.emailconfig import ThreepidBehaviour
from synapse.http.client import SimpleHttpClient from synapse.http.client import SimpleHttpClient
from synapse.types import JsonDict, Requester
from synapse.util.hash import sha256_and_url_safe_base64 from synapse.util.hash import sha256_and_url_safe_base64
from synapse.util.stringutils import assert_valid_client_secret, random_string from synapse.util.stringutils import assert_valid_client_secret, random_string
@ -59,23 +61,23 @@ class IdentityHandler(BaseHandler):
self.federation_http_client = hs.get_http_client() self.federation_http_client = hs.get_http_client()
self.hs = hs self.hs = hs
async def threepid_from_creds(self, id_server, creds): async def threepid_from_creds(
self, id_server: str, creds: Dict[str, str]
) -> Optional[JsonDict]:
""" """
Retrieve and validate a threepid identifier from a "credentials" dictionary against a Retrieve and validate a threepid identifier from a "credentials" dictionary against a
given identity server given identity server
Args: Args:
id_server (str): The identity server to validate 3PIDs against. Must be a id_server: The identity server to validate 3PIDs against. Must be a
complete URL including the protocol (http(s)://) complete URL including the protocol (http(s)://)
creds: Dictionary containing the following keys:
creds (dict[str, str]): Dictionary containing the following keys:
* client_secret|clientSecret: A unique secret str provided by the client * client_secret|clientSecret: A unique secret str provided by the client
* sid: The ID of the validation session * sid: The ID of the validation session
Returns: Returns:
Deferred[dict[str,str|int]|None]: A dictionary consisting of response params to A dictionary consisting of response params to the /getValidated3pid
the /getValidated3pid endpoint of the Identity Service API, or None if the endpoint of the Identity Service API, or None if the threepid was not found
threepid was not found
""" """
client_secret = creds.get("client_secret") or creds.get("clientSecret") client_secret = creds.get("client_secret") or creds.get("clientSecret")
if not client_secret: if not client_secret:
@ -119,26 +121,27 @@ class IdentityHandler(BaseHandler):
return None return None
async def bind_threepid( async def bind_threepid(
self, client_secret, sid, mxid, id_server, id_access_token=None, use_v2=True self,
): client_secret: str,
sid: str,
mxid: str,
id_server: str,
id_access_token: Optional[str] = None,
use_v2: bool = True,
) -> JsonDict:
"""Bind a 3PID to an identity server """Bind a 3PID to an identity server
Args: Args:
client_secret (str): A unique secret provided by the client client_secret: A unique secret provided by the client
sid: The ID of the validation session
sid (str): The ID of the validation session mxid: The MXID to bind the 3PID to
id_server: The domain of the identity server to query
mxid (str): The MXID to bind the 3PID to id_access_token: The access token to authenticate to the identity
id_server (str): The domain of the identity server to query
id_access_token (str): The access token to authenticate to the identity
server with, if necessary. Required if use_v2 is true server with, if necessary. Required if use_v2 is true
use_v2: Whether to use v2 Identity Service API endpoints. Defaults to True
use_v2 (bool): Whether to use v2 Identity Service API endpoints. Defaults to True
Returns: Returns:
Deferred[dict]: The response from the identity server The response from the identity server
""" """
logger.debug("Proxying threepid bind request for %s to %s", mxid, id_server) logger.debug("Proxying threepid bind request for %s to %s", mxid, id_server)
@ -151,7 +154,7 @@ class IdentityHandler(BaseHandler):
bind_data = {"sid": sid, "client_secret": client_secret, "mxid": mxid} bind_data = {"sid": sid, "client_secret": client_secret, "mxid": mxid}
if use_v2: if use_v2:
bind_url = "https://%s/_matrix/identity/v2/3pid/bind" % (id_server,) bind_url = "https://%s/_matrix/identity/v2/3pid/bind" % (id_server,)
headers["Authorization"] = create_id_access_token_header(id_access_token) headers["Authorization"] = create_id_access_token_header(id_access_token) # type: ignore
else: else:
bind_url = "https://%s/_matrix/identity/api/v1/3pid/bind" % (id_server,) bind_url = "https://%s/_matrix/identity/api/v1/3pid/bind" % (id_server,)
@ -187,20 +190,20 @@ class IdentityHandler(BaseHandler):
) )
return res return res
async def try_unbind_threepid(self, mxid, threepid): async def try_unbind_threepid(self, mxid: str, threepid: dict) -> bool:
"""Attempt to remove a 3PID from an identity server, or if one is not provided, all """Attempt to remove a 3PID from an identity server, or if one is not provided, all
identity servers we're aware the binding is present on identity servers we're aware the binding is present on
Args: Args:
mxid (str): Matrix user ID of binding to be removed mxid: Matrix user ID of binding to be removed
threepid (dict): Dict with medium & address of binding to be threepid: Dict with medium & address of binding to be
removed, and an optional id_server. removed, and an optional id_server.
Raises: Raises:
SynapseError: If we failed to contact the identity server SynapseError: If we failed to contact the identity server
Returns: Returns:
Deferred[bool]: True on success, otherwise False if the identity True on success, otherwise False if the identity
server doesn't support unbinding (or no identity server found to server doesn't support unbinding (or no identity server found to
contact). contact).
""" """
@ -223,19 +226,21 @@ class IdentityHandler(BaseHandler):
return changed return changed
async def try_unbind_threepid_with_id_server(self, mxid, threepid, id_server): async def try_unbind_threepid_with_id_server(
self, mxid: str, threepid: dict, id_server: str
) -> bool:
"""Removes a binding from an identity server """Removes a binding from an identity server
Args: Args:
mxid (str): Matrix user ID of binding to be removed mxid: Matrix user ID of binding to be removed
threepid (dict): Dict with medium & address of binding to be removed threepid: Dict with medium & address of binding to be removed
id_server (str): Identity server to unbind from id_server: Identity server to unbind from
Raises: Raises:
SynapseError: If we failed to contact the identity server SynapseError: If we failed to contact the identity server
Returns: Returns:
Deferred[bool]: True on success, otherwise False if the identity True on success, otherwise False if the identity
server doesn't support unbinding server doesn't support unbinding
""" """
url = "https://%s/_matrix/identity/api/v1/3pid/unbind" % (id_server,) url = "https://%s/_matrix/identity/api/v1/3pid/unbind" % (id_server,)
@ -287,23 +292,23 @@ class IdentityHandler(BaseHandler):
async def send_threepid_validation( async def send_threepid_validation(
self, self,
email_address, email_address: str,
client_secret, client_secret: str,
send_attempt, send_attempt: int,
send_email_func, send_email_func: Callable[[str, str, str, str], Awaitable],
next_link=None, next_link: Optional[str] = None,
): ) -> str:
"""Send a threepid validation email for password reset or """Send a threepid validation email for password reset or
registration purposes registration purposes
Args: Args:
email_address (str): The user's email address email_address: The user's email address
client_secret (str): The provided client secret client_secret: The provided client secret
send_attempt (int): Which send attempt this is send_attempt: Which send attempt this is
send_email_func (func): A function that takes an email address, token, send_email_func: A function that takes an email address, token,
client_secret and session_id, sends an email client_secret and session_id, sends an email
and returns a Deferred. and returns an Awaitable.
next_link (str|None): The URL to redirect the user to after validation next_link: The URL to redirect the user to after validation
Returns: Returns:
The new session_id upon success The new session_id upon success
@ -372,17 +377,22 @@ class IdentityHandler(BaseHandler):
return session_id return session_id
async def requestEmailToken( async def requestEmailToken(
self, id_server, email, client_secret, send_attempt, next_link=None self,
): id_server: str,
email: str,
client_secret: str,
send_attempt: int,
next_link: Optional[str] = None,
) -> JsonDict:
""" """
Request an external server send an email on our behalf for the purposes of threepid Request an external server send an email on our behalf for the purposes of threepid
validation. validation.
Args: Args:
id_server (str): The identity server to proxy to id_server: The identity server to proxy to
email (str): The email to send the message to email: The email to send the message to
client_secret (str): The unique client_secret sends by the user client_secret: The unique client_secret sends by the user
send_attempt (int): Which attempt this is send_attempt: Which attempt this is
next_link: A link to redirect the user to once they submit the token next_link: A link to redirect the user to once they submit the token
Returns: Returns:
@ -419,22 +429,22 @@ class IdentityHandler(BaseHandler):
async def requestMsisdnToken( async def requestMsisdnToken(
self, self,
id_server, id_server: str,
country, country: str,
phone_number, phone_number: str,
client_secret, client_secret: str,
send_attempt, send_attempt: int,
next_link=None, next_link: Optional[str] = None,
): ) -> JsonDict:
""" """
Request an external server send an SMS message on our behalf for the purposes of Request an external server send an SMS message on our behalf for the purposes of
threepid validation. threepid validation.
Args: Args:
id_server (str): The identity server to proxy to id_server: The identity server to proxy to
country (str): The country code of the phone number country: The country code of the phone number
phone_number (str): The number to send the message to phone_number: The number to send the message to
client_secret (str): The unique client_secret sends by the user client_secret: The unique client_secret sends by the user
send_attempt (int): Which attempt this is send_attempt: Which attempt this is
next_link: A link to redirect the user to once they submit the token next_link: A link to redirect the user to once they submit the token
Returns: Returns:
@ -480,17 +490,18 @@ class IdentityHandler(BaseHandler):
) )
return data return data
async def validate_threepid_session(self, client_secret, sid): async def validate_threepid_session(
self, client_secret: str, sid: str
) -> Optional[JsonDict]:
"""Validates a threepid session with only the client secret and session ID """Validates a threepid session with only the client secret and session ID
Tries validating against any configured account_threepid_delegates as well as locally. Tries validating against any configured account_threepid_delegates as well as locally.
Args: Args:
client_secret (str): A secret provided by the client client_secret: A secret provided by the client
sid: The ID of the session
sid (str): The ID of the session
Returns: Returns:
Dict[str, str|int] if validation was successful, otherwise None The json response if validation was successful, otherwise None
""" """
# XXX: We shouldn't need to keep wrapping and unwrapping this value # XXX: We shouldn't need to keep wrapping and unwrapping this value
threepid_creds = {"client_secret": client_secret, "sid": sid} threepid_creds = {"client_secret": client_secret, "sid": sid}
@ -523,23 +534,22 @@ class IdentityHandler(BaseHandler):
return validation_session return validation_session
async def proxy_msisdn_submit_token(self, id_server, client_secret, sid, token): async def proxy_msisdn_submit_token(
self, id_server: str, client_secret: str, sid: str, token: str
) -> JsonDict:
"""Proxy a POST submitToken request to an identity server for verification purposes """Proxy a POST submitToken request to an identity server for verification purposes
Args: Args:
id_server (str): The identity server URL to contact id_server: The identity server URL to contact
client_secret: Secret provided by the client
client_secret (str): Secret provided by the client sid: The ID of the session
token: The verification token
sid (str): The ID of the session
token (str): The verification token
Raises: Raises:
SynapseError: If we failed to contact the identity server SynapseError: If we failed to contact the identity server
Returns: Returns:
Deferred[dict]: The response dict from the identity server The response dict from the identity server
""" """
body = {"client_secret": client_secret, "sid": sid, "token": token} body = {"client_secret": client_secret, "sid": sid, "token": token}
@ -554,19 +564,25 @@ class IdentityHandler(BaseHandler):
logger.warning("Error contacting msisdn account_threepid_delegate: %s", e) logger.warning("Error contacting msisdn account_threepid_delegate: %s", e)
raise SynapseError(400, "Error contacting the identity server") raise SynapseError(400, "Error contacting the identity server")
async def lookup_3pid(self, id_server, medium, address, id_access_token=None): async def lookup_3pid(
self,
id_server: str,
medium: str,
address: str,
id_access_token: Optional[str] = None,
) -> Optional[str]:
"""Looks up a 3pid in the passed identity server. """Looks up a 3pid in the passed identity server.
Args: Args:
id_server (str): The server name (including port, if required) id_server: The server name (including port, if required)
of the identity server to use. of the identity server to use.
medium (str): The type of the third party identifier (e.g. "email"). medium: The type of the third party identifier (e.g. "email").
address (str): The third party identifier (e.g. "foo@example.com"). address: The third party identifier (e.g. "foo@example.com").
id_access_token (str|None): The access token to authenticate to the identity id_access_token: The access token to authenticate to the identity
server with server with
Returns: Returns:
str|None: the matrix ID of the 3pid, or None if it is not recognized. the matrix ID of the 3pid, or None if it is not recognized.
""" """
if id_access_token is not None: if id_access_token is not None:
try: try:
@ -591,17 +607,19 @@ class IdentityHandler(BaseHandler):
return await self._lookup_3pid_v1(id_server, medium, address) return await self._lookup_3pid_v1(id_server, medium, address)
async def _lookup_3pid_v1(self, id_server, medium, address): async def _lookup_3pid_v1(
self, id_server: str, medium: str, address: str
) -> Optional[str]:
"""Looks up a 3pid in the passed identity server using v1 lookup. """Looks up a 3pid in the passed identity server using v1 lookup.
Args: Args:
id_server (str): The server name (including port, if required) id_server: The server name (including port, if required)
of the identity server to use. of the identity server to use.
medium (str): The type of the third party identifier (e.g. "email"). medium: The type of the third party identifier (e.g. "email").
address (str): The third party identifier (e.g. "foo@example.com"). address: The third party identifier (e.g. "foo@example.com").
Returns: Returns:
str: the matrix ID of the 3pid, or None if it is not recognized. the matrix ID of the 3pid, or None if it is not recognized.
""" """
try: try:
data = await self.blacklisting_http_client.get_json( data = await self.blacklisting_http_client.get_json(
@ -621,18 +639,20 @@ class IdentityHandler(BaseHandler):
return None return None
async def _lookup_3pid_v2(self, id_server, id_access_token, medium, address): async def _lookup_3pid_v2(
self, id_server: str, id_access_token: str, medium: str, address: str
) -> Optional[str]:
"""Looks up a 3pid in the passed identity server using v2 lookup. """Looks up a 3pid in the passed identity server using v2 lookup.
Args: Args:
id_server (str): The server name (including port, if required) id_server: The server name (including port, if required)
of the identity server to use. of the identity server to use.
id_access_token (str): The access token to authenticate to the identity server with id_access_token: The access token to authenticate to the identity server with
medium (str): The type of the third party identifier (e.g. "email"). medium: The type of the third party identifier (e.g. "email").
address (str): The third party identifier (e.g. "foo@example.com"). address: The third party identifier (e.g. "foo@example.com").
Returns: Returns:
Deferred[str|None]: the matrix ID of the 3pid, or None if it is not recognised. the matrix ID of the 3pid, or None if it is not recognised.
""" """
# Check what hashing details are supported by this identity server # Check what hashing details are supported by this identity server
try: try:
@ -757,49 +777,48 @@ class IdentityHandler(BaseHandler):
async def ask_id_server_for_third_party_invite( async def ask_id_server_for_third_party_invite(
self, self,
requester, requester: Requester,
id_server, id_server: str,
medium, medium: str,
address, address: str,
room_id, room_id: str,
inviter_user_id, inviter_user_id: str,
room_alias, room_alias: str,
room_avatar_url, room_avatar_url: str,
room_join_rules, room_join_rules: str,
room_name, room_name: str,
inviter_display_name, inviter_display_name: str,
inviter_avatar_url, inviter_avatar_url: str,
id_access_token=None, id_access_token: Optional[str] = None,
): ) -> Tuple[str, List[Dict[str, str]], Dict[str, str], str]:
""" """
Asks an identity server for a third party invite. Asks an identity server for a third party invite.
Args: Args:
requester (Requester) requester
id_server (str): hostname + optional port for the identity server. id_server: hostname + optional port for the identity server.
medium (str): The literal string "email". medium: The literal string "email".
address (str): The third party address being invited. address: The third party address being invited.
room_id (str): The ID of the room to which the user is invited. room_id: The ID of the room to which the user is invited.
inviter_user_id (str): The user ID of the inviter. inviter_user_id: The user ID of the inviter.
room_alias (str): An alias for the room, for cosmetic notifications. room_alias: An alias for the room, for cosmetic notifications.
room_avatar_url (str): The URL of the room's avatar, for cosmetic room_avatar_url: The URL of the room's avatar, for cosmetic
notifications. notifications.
room_join_rules (str): The join rules of the email (e.g. "public"). room_join_rules: The join rules of the email (e.g. "public").
room_name (str): The m.room.name of the room. room_name: The m.room.name of the room.
inviter_display_name (str): The current display name of the inviter_display_name: The current display name of the
inviter. inviter.
inviter_avatar_url (str): The URL of the inviter's avatar. inviter_avatar_url: The URL of the inviter's avatar.
id_access_token (str|None): The access token to authenticate to the identity id_access_token (str|None): The access token to authenticate to the identity
server with server with
Returns: Returns:
A deferred tuple containing: A tuple containing:
token (str): The token which must be signed to prove authenticity. token: The token which must be signed to prove authenticity.
public_keys ([{"public_key": str, "key_validity_url": str}]): public_keys ([{"public_key": str, "key_validity_url": str}]):
public_key is a base64-encoded ed25519 public key. public_key is a base64-encoded ed25519 public key.
fallback_public_key: One element from public_keys. fallback_public_key: One element from public_keys.
display_name (str): A user-friendly name to represent the invited display_name: A user-friendly name to represent the invited user.
user.
""" """
invite_config = { invite_config = {
"medium": medium, "medium": medium,
@ -896,15 +915,15 @@ class IdentityHandler(BaseHandler):
return token, public_keys, fallback_public_key, display_name return token, public_keys, fallback_public_key, display_name
def create_id_access_token_header(id_access_token): def create_id_access_token_header(id_access_token: str) -> List[str]:
"""Create an Authorization header for passing to SimpleHttpClient as the header value """Create an Authorization header for passing to SimpleHttpClient as the header value
of an HTTP request. of an HTTP request.
Args: Args:
id_access_token (str): An identity server access token. id_access_token: An identity server access token.
Returns: Returns:
list[str]: The ascii-encoded bearer token encased in a list. The ascii-encoded bearer token encased in a list.
""" """
# Prefix with Bearer # Prefix with Bearer
bearer_token = "Bearer %s" % id_access_token bearer_token = "Bearer %s" % id_access_token

View file

@ -119,7 +119,7 @@ class RoomCreationHandler(BaseHandler):
async def upgrade_room( async def upgrade_room(
self, requester: Requester, old_room_id: str, new_version: RoomVersion self, requester: Requester, old_room_id: str, new_version: RoomVersion
): ) -> str:
"""Replace a room with a new room with a different version """Replace a room with a new room with a different version
Args: Args:
@ -128,7 +128,7 @@ class RoomCreationHandler(BaseHandler):
new_version: the new room version to use new_version: the new room version to use
Returns: Returns:
Deferred[unicode]: the new room id the new room id
""" """
await self.ratelimit(requester) await self.ratelimit(requester)
@ -239,7 +239,7 @@ class RoomCreationHandler(BaseHandler):
old_room_id: str, old_room_id: str,
new_room_id: str, new_room_id: str,
old_room_state: StateMap[str], old_room_state: StateMap[str],
): ) -> None:
"""Send updated power levels in both rooms after an upgrade """Send updated power levels in both rooms after an upgrade
Args: Args:
@ -247,9 +247,6 @@ class RoomCreationHandler(BaseHandler):
old_room_id: the id of the room to be replaced old_room_id: the id of the room to be replaced
new_room_id: the id of the replacement room new_room_id: the id of the replacement room
old_room_state: the state map for the old room old_room_state: the state map for the old room
Returns:
Deferred
""" """
old_room_pl_event_id = old_room_state.get((EventTypes.PowerLevels, "")) old_room_pl_event_id = old_room_state.get((EventTypes.PowerLevels, ""))
@ -322,7 +319,7 @@ class RoomCreationHandler(BaseHandler):
new_room_id: str, new_room_id: str,
new_room_version: RoomVersion, new_room_version: RoomVersion,
tombstone_event_id: str, tombstone_event_id: str,
): ) -> None:
"""Populate a new room based on an old room """Populate a new room based on an old room
Args: Args:
@ -332,8 +329,6 @@ class RoomCreationHandler(BaseHandler):
created with _gemerate_room_id()) created with _gemerate_room_id())
new_room_version: the new room version to use new_room_version: the new room version to use
tombstone_event_id: the ID of the tombstone event in the old room. tombstone_event_id: the ID of the tombstone event in the old room.
Returns:
Deferred
""" """
user_id = requester.user.to_string() user_id = requester.user.to_string()

View file

@ -15,6 +15,7 @@
import itertools import itertools
import logging import logging
from typing import Iterable
from unpaddedbase64 import decode_base64, encode_base64 from unpaddedbase64 import decode_base64, encode_base64
@ -37,7 +38,7 @@ class SearchHandler(BaseHandler):
self.state_store = self.storage.state self.state_store = self.storage.state
self.auth = hs.get_auth() self.auth = hs.get_auth()
async def get_old_rooms_from_upgraded_room(self, room_id): async def get_old_rooms_from_upgraded_room(self, room_id: str) -> Iterable[str]:
"""Retrieves room IDs of old rooms in the history of an upgraded room. """Retrieves room IDs of old rooms in the history of an upgraded room.
We do so by checking the m.room.create event of the room for a We do so by checking the m.room.create event of the room for a
@ -48,10 +49,10 @@ class SearchHandler(BaseHandler):
The full list of all found rooms in then returned. The full list of all found rooms in then returned.
Args: Args:
room_id (str): id of the room to search through. room_id: id of the room to search through.
Returns: Returns:
Deferred[iterable[str]]: predecessor room ids Predecessor room ids
""" """
historical_room_ids = [] historical_room_ids = []

View file

@ -421,10 +421,6 @@ class SyncHandler(object):
potential_recents: Optional[List[EventBase]] = None, potential_recents: Optional[List[EventBase]] = None,
newly_joined_room: bool = False, newly_joined_room: bool = False,
) -> TimelineBatch: ) -> TimelineBatch:
"""
Returns:
a Deferred TimelineBatch
"""
with Measure(self.clock, "load_filtered_recents"): with Measure(self.clock, "load_filtered_recents"):
timeline_limit = sync_config.filter_collection.timeline_limit() timeline_limit = sync_config.filter_collection.timeline_limit()
block_all_timeline = ( block_all_timeline = (

View file

@ -185,6 +185,7 @@ commands = mypy \
synapse/handlers/cas_handler.py \ synapse/handlers/cas_handler.py \
synapse/handlers/directory.py \ synapse/handlers/directory.py \
synapse/handlers/federation.py \ synapse/handlers/federation.py \
synapse/handlers/identity.py \
synapse/handlers/oidc_handler.py \ synapse/handlers/oidc_handler.py \
synapse/handlers/presence.py \ synapse/handlers/presence.py \
synapse/handlers/room_member.py \ synapse/handlers/room_member.py \