Use type hinting generics in standard collections (#19046)

aka PEP 585, added in Python 3.9

 - https://peps.python.org/pep-0585/
 - https://docs.astral.sh/ruff/rules/non-pep585-annotation/
This commit is contained in:
Andrew Ferrazzutti
2025-10-22 17:48:19 -04:00
committed by GitHub
parent cba3a814c6
commit fc244bb592
539 changed files with 4599 additions and 5066 deletions
+20 -23
View File
@@ -26,13 +26,10 @@ from typing import (
Awaitable,
Callable,
Collection,
Dict,
Generator,
Iterable,
List,
Mapping,
Optional,
Tuple,
TypeVar,
Union,
)
@@ -559,7 +556,7 @@ class ModuleApi:
check_3pid_auth: Optional[CHECK_3PID_AUTH_CALLBACK] = None,
on_logged_out: Optional[ON_LOGGED_OUT_CALLBACK] = None,
auth_checkers: Optional[
Dict[Tuple[str, Tuple[str, ...]], CHECK_AUTH_CALLBACK]
dict[tuple[str, tuple[str, ...]], CHECK_AUTH_CALLBACK]
] = None,
is_3pid_allowed: Optional[IS_3PID_ALLOWED_CALLBACK] = None,
get_username_for_registration: Optional[
@@ -829,7 +826,7 @@ class ModuleApi:
user_id = UserID.from_string(f"@{localpart}:{server_name}")
return await self._store.get_profileinfo(user_id)
async def get_threepids_for_user(self, user_id: str) -> List[Dict[str, str]]:
async def get_threepids_for_user(self, user_id: str) -> list[dict[str, str]]:
"""Look up the threepids (email addresses and phone numbers) associated with the
given Matrix user ID.
@@ -865,8 +862,8 @@ class ModuleApi:
self,
localpart: str,
displayname: Optional[str] = None,
emails: Optional[List[str]] = None,
) -> Generator["defer.Deferred[Any]", Any, Tuple[str, str]]:
emails: Optional[list[str]] = None,
) -> Generator["defer.Deferred[Any]", Any, tuple[str, str]]:
"""Registers a new user with given localpart and optional displayname, emails.
Also returns an access token for the new user.
@@ -896,7 +893,7 @@ class ModuleApi:
self,
localpart: str,
displayname: Optional[str] = None,
emails: Optional[List[str]] = None,
emails: Optional[list[str]] = None,
admin: bool = False,
) -> "defer.Deferred[str]":
"""Registers a new user with given localpart and optional displayname, emails.
@@ -931,7 +928,7 @@ class ModuleApi:
user_id: str,
device_id: Optional[str] = None,
initial_display_name: Optional[str] = None,
) -> "defer.Deferred[Tuple[str, str, Optional[int], Optional[str]]]":
) -> "defer.Deferred[tuple[str, str, Optional[int], Optional[str]]]":
"""Register a device for a user and generate an access token.
Added in Synapse v1.2.0.
@@ -1085,7 +1082,7 @@ class ModuleApi:
)
async def invalidate_cache(
self, cached_func: CachedFunction, keys: Tuple[Any, ...]
self, cached_func: CachedFunction, keys: tuple[Any, ...]
) -> None:
"""Invalidate a cache entry of a cached function across workers. The cached function
needs to be registered on all workers first with `register_cached_function`.
@@ -1138,7 +1135,7 @@ class ModuleApi:
@defer.inlineCallbacks
def get_state_events_in_room(
self, room_id: str, types: Iterable[Tuple[str, Optional[str]]]
self, room_id: str, types: Iterable[tuple[str, Optional[str]]]
) -> Generator[defer.Deferred, Any, Iterable[EventBase]]:
"""Gets current state events for the given room.
@@ -1170,7 +1167,7 @@ class ModuleApi:
room_id: str,
new_membership: str,
content: Optional[JsonDict] = None,
remote_room_hosts: Optional[List[str]] = None,
remote_room_hosts: Optional[list[str]] = None,
) -> EventBase:
"""Updates the membership of a user to the given value.
@@ -1346,7 +1343,7 @@ class ModuleApi:
)
async def set_presence_for_users(
self, users: Mapping[str, Tuple[str, Optional[str]]]
self, users: Mapping[str, tuple[str, Optional[str]]]
) -> None:
"""
Update the internal presence state of users.
@@ -1490,7 +1487,7 @@ class ModuleApi:
content: JsonDict,
tweaks: Optional[JsonMapping] = None,
default_payload: Optional[JsonMapping] = None,
) -> Dict[str, bool]:
) -> dict[str, bool]:
"""Send an HTTP push notification that is forwarded to the registered push gateway
for the specified user/device.
@@ -1554,9 +1551,9 @@ class ModuleApi:
def read_templates(
self,
filenames: List[str],
filenames: list[str],
custom_template_directory: Optional[str] = None,
) -> List[jinja2.Template]:
) -> list[jinja2.Template]:
"""Read and load the content of the template files at the given location.
By default, Synapse will look for these templates in its configured template
directory, but another directory to search in can be provided.
@@ -1595,7 +1592,7 @@ class ModuleApi:
async def get_user_ip_and_agents(
self, user_id: str, since_ts: int = 0
) -> List[UserIpAndAgent]:
) -> list[UserIpAndAgent]:
"""
Return the list of user IPs and agents for a user.
@@ -1638,7 +1635,7 @@ class ModuleApi:
async def get_room_state(
self,
room_id: str,
event_filter: Optional[Iterable[Tuple[str, Optional[str]]]] = None,
event_filter: Optional[Iterable[tuple[str, Optional[str]]]] = None,
) -> StateMap[EventBase]:
"""Returns the current state of the given room.
@@ -1803,7 +1800,7 @@ class ModuleApi:
await self._store.add_user_bound_threepid(user_id, medium, address, id_server)
def check_push_rule_actions(
self, actions: List[Union[str, Dict[str, str]]]
self, actions: list[Union[str, dict[str, str]]]
) -> None:
"""Checks if the given push rule actions are valid according to the Matrix
specification.
@@ -1827,7 +1824,7 @@ class ModuleApi:
scope: str,
kind: str,
rule_id: str,
actions: List[Union[str, Dict[str, str]]],
actions: list[Union[str, dict[str, str]]],
) -> None:
"""Changes the actions of an existing push rule for the given user.
@@ -1866,7 +1863,7 @@ class ModuleApi:
async def get_monthly_active_users_by_service(
self, start_timestamp: Optional[int] = None, end_timestamp: Optional[int] = None
) -> List[Tuple[str, str]]:
) -> list[tuple[str, str]]:
"""Generates list of monthly active users and their services.
Please see corresponding storage docstring for more details.
@@ -1912,7 +1909,7 @@ class ModuleApi:
return RoomAlias.from_string(room_alias_str)
return None
async def lookup_room_alias(self, room_alias: str) -> Tuple[str, List[str]]:
async def lookup_room_alias(self, room_alias: str) -> tuple[str, list[str]]:
"""
Get the room ID associated with a room alias.
@@ -1942,7 +1939,7 @@ class ModuleApi:
config: JsonDict,
ratelimit: bool = True,
creator_join_profile: Optional[JsonDict] = None,
) -> Tuple[str, Optional[str]]:
) -> tuple[str, Optional[str]]:
"""Creates a new room.
Added in Synapse v1.65.0.
@@ -20,7 +20,7 @@
#
import logging
from typing import Awaitable, Callable, List, Optional, Tuple
from typing import Awaitable, Callable, Optional
from twisted.web.http import Request
@@ -33,15 +33,15 @@ ON_USER_LOGIN_CALLBACK = Callable[[str, Optional[str], Optional[str]], Awaitable
# Temporary hooks to allow for a transition from `/_matrix/client` endpoints
# to `/_synapse/client/account_validity`. See `register_callbacks` below.
ON_LEGACY_SEND_MAIL_CALLBACK = Callable[[str], Awaitable]
ON_LEGACY_RENEW_CALLBACK = Callable[[str], Awaitable[Tuple[bool, bool, int]]]
ON_LEGACY_RENEW_CALLBACK = Callable[[str], Awaitable[tuple[bool, bool, int]]]
ON_LEGACY_ADMIN_REQUEST = Callable[[Request], Awaitable]
class AccountValidityModuleApiCallbacks:
def __init__(self) -> None:
self.is_user_expired_callbacks: List[IS_USER_EXPIRED_CALLBACK] = []
self.on_user_registration_callbacks: List[ON_USER_REGISTRATION_CALLBACK] = []
self.on_user_login_callbacks: List[ON_USER_LOGIN_CALLBACK] = []
self.is_user_expired_callbacks: list[IS_USER_EXPIRED_CALLBACK] = []
self.on_user_registration_callbacks: list[ON_USER_REGISTRATION_CALLBACK] = []
self.on_user_login_callbacks: list[ON_USER_LOGIN_CALLBACK] = []
self.on_legacy_send_mail_callback: Optional[ON_LEGACY_SEND_MAIL_CALLBACK] = None
self.on_legacy_renew_callback: Optional[ON_LEGACY_RENEW_CALLBACK] = None
@@ -13,7 +13,7 @@
#
import logging
from typing import TYPE_CHECKING, Awaitable, Callable, List, Optional
from typing import TYPE_CHECKING, Awaitable, Callable, Optional
from synapse.config.repository import MediaUploadLimit
from synapse.types import JsonDict
@@ -30,7 +30,7 @@ GET_MEDIA_CONFIG_FOR_USER_CALLBACK = Callable[[str], Awaitable[Optional[JsonDict
IS_USER_ALLOWED_TO_UPLOAD_MEDIA_OF_SIZE_CALLBACK = Callable[[str, int], Awaitable[bool]]
GET_MEDIA_UPLOAD_LIMITS_FOR_USER_CALLBACK = Callable[
[str], Awaitable[Optional[List[MediaUploadLimit]]]
[str], Awaitable[Optional[list[MediaUploadLimit]]]
]
ON_MEDIA_UPLOAD_LIMIT_EXCEEDED_CALLBACK = Callable[
@@ -42,16 +42,16 @@ class MediaRepositoryModuleApiCallbacks:
def __init__(self, hs: "HomeServer") -> None:
self.server_name = hs.hostname
self.clock = hs.get_clock()
self._get_media_config_for_user_callbacks: List[
self._get_media_config_for_user_callbacks: list[
GET_MEDIA_CONFIG_FOR_USER_CALLBACK
] = []
self._is_user_allowed_to_upload_media_of_size_callbacks: List[
self._is_user_allowed_to_upload_media_of_size_callbacks: list[
IS_USER_ALLOWED_TO_UPLOAD_MEDIA_OF_SIZE_CALLBACK
] = []
self._get_media_upload_limits_for_user_callbacks: List[
self._get_media_upload_limits_for_user_callbacks: list[
GET_MEDIA_UPLOAD_LIMITS_FOR_USER_CALLBACK
] = []
self._on_media_upload_limit_exceeded_callbacks: List[
self._on_media_upload_limit_exceeded_callbacks: list[
ON_MEDIA_UPLOAD_LIMIT_EXCEEDED_CALLBACK
] = []
@@ -117,7 +117,7 @@ class MediaRepositoryModuleApiCallbacks:
async def get_media_upload_limits_for_user(
self, user_id: str
) -> Optional[List[MediaUploadLimit]]:
) -> Optional[list[MediaUploadLimit]]:
"""
Get the first non-None list of MediaUploadLimits for the user from the registered callbacks.
If a list is returned it will be sorted in descending order of duration.
@@ -128,7 +128,7 @@ class MediaRepositoryModuleApiCallbacks:
name=f"{callback.__module__}.{callback.__qualname__}",
server_name=self.server_name,
):
res: Optional[List[MediaUploadLimit]] = await delay_cancellation(
res: Optional[list[MediaUploadLimit]] = await delay_cancellation(
callback(user_id)
)
if res is not None: # to allow [] to be returned meaning no limit
@@ -13,7 +13,7 @@
#
import logging
from typing import TYPE_CHECKING, Awaitable, Callable, List, Optional
from typing import TYPE_CHECKING, Awaitable, Callable, Optional
import attr
@@ -45,7 +45,7 @@ class RatelimitModuleApiCallbacks:
def __init__(self, hs: "HomeServer") -> None:
self.server_name = hs.hostname
self.clock = hs.get_clock()
self._get_ratelimit_override_for_user_callbacks: List[
self._get_ratelimit_override_for_user_callbacks: list[
GET_RATELIMIT_OVERRIDE_FOR_USER_CALLBACK
] = []
@@ -29,10 +29,8 @@ from typing import (
Awaitable,
Callable,
Collection,
List,
Literal,
Optional,
Tuple,
Union,
cast,
)
@@ -63,7 +61,7 @@ CHECK_EVENT_FOR_SPAM_CALLBACK = Callable[
# disappear without warning depending on the results of ongoing
# experiments.
# Use this to return additional information as part of an error.
Tuple[Codes, JsonDict],
tuple[Codes, JsonDict],
# Deprecated
bool,
]
@@ -83,7 +81,7 @@ USER_MAY_JOIN_ROOM_CALLBACK = Callable[
# disappear without warning depending on the results of ongoing
# experiments.
# Use this to return additional information as part of an error.
Tuple[Codes, JsonDict],
tuple[Codes, JsonDict],
# Deprecated
bool,
]
@@ -99,7 +97,7 @@ USER_MAY_INVITE_CALLBACK = Callable[
# disappear without warning depending on the results of ongoing
# experiments.
# Use this to return additional information as part of an error.
Tuple[Codes, JsonDict],
tuple[Codes, JsonDict],
# Deprecated
bool,
]
@@ -115,7 +113,7 @@ FEDERATED_USER_MAY_INVITE_CALLBACK = Callable[
# disappear without warning depending on the results of ongoing
# experiments.
# Use this to return additional information as part of an error.
Tuple[Codes, JsonDict],
tuple[Codes, JsonDict],
# Deprecated
bool,
]
@@ -131,7 +129,7 @@ USER_MAY_SEND_3PID_INVITE_CALLBACK = Callable[
# disappear without warning depending on the results of ongoing
# experiments.
# Use this to return additional information as part of an error.
Tuple[Codes, JsonDict],
tuple[Codes, JsonDict],
# Deprecated
bool,
]
@@ -144,7 +142,7 @@ USER_MAY_CREATE_ROOM_CALLBACK_RETURN_VALUE = Union[
# disappear without warning depending on the results of ongoing
# experiments.
# Use this to return additional information as part of an error.
Tuple[Codes, JsonDict],
tuple[Codes, JsonDict],
# Deprecated
bool,
]
@@ -167,7 +165,7 @@ USER_MAY_CREATE_ROOM_ALIAS_CALLBACK = Callable[
# disappear without warning depending on the results of ongoing
# experiments.
# Use this to return additional information as part of an error.
Tuple[Codes, JsonDict],
tuple[Codes, JsonDict],
# Deprecated
bool,
]
@@ -183,7 +181,7 @@ USER_MAY_PUBLISH_ROOM_CALLBACK = Callable[
# disappear without warning depending on the results of ongoing
# experiments.
# Use this to return additional information as part of an error.
Tuple[Codes, JsonDict],
tuple[Codes, JsonDict],
# Deprecated
bool,
]
@@ -199,7 +197,7 @@ USER_MAY_SEND_STATE_EVENT_CALLBACK = Callable[
# disappear without warning depending on the results of ongoing
# experiments.
# Use this to return additional information as part of an error.
Tuple[Codes, JsonDict],
tuple[Codes, JsonDict],
]
],
]
@@ -211,7 +209,7 @@ LEGACY_CHECK_REGISTRATION_FOR_SPAM_CALLBACK = Callable[
[
Optional[dict],
Optional[str],
Collection[Tuple[str, str]],
Collection[tuple[str, str]],
],
Awaitable[RegistrationBehaviour],
]
@@ -219,7 +217,7 @@ CHECK_REGISTRATION_FOR_SPAM_CALLBACK = Callable[
[
Optional[dict],
Optional[str],
Collection[Tuple[str, str]],
Collection[tuple[str, str]],
Optional[str],
],
Awaitable[RegistrationBehaviour],
@@ -234,7 +232,7 @@ CHECK_MEDIA_FILE_FOR_SPAM_CALLBACK = Callable[
# disappear without warning depending on the results of ongoing
# experiments.
# Use this to return additional information as part of an error.
Tuple[Codes, JsonDict],
tuple[Codes, JsonDict],
# Deprecated
bool,
]
@@ -245,7 +243,7 @@ CHECK_LOGIN_FOR_SPAM_CALLBACK = Callable[
str,
Optional[str],
Optional[str],
Collection[Tuple[Optional[str], str]],
Collection[tuple[Optional[str], str]],
Optional[str],
],
Awaitable[
@@ -256,7 +254,7 @@ CHECK_LOGIN_FOR_SPAM_CALLBACK = Callable[
# disappear without warning depending on the results of ongoing
# experiments.
# Use this to return additional information as part of an error.
Tuple[Codes, JsonDict],
tuple[Codes, JsonDict],
]
],
]
@@ -266,7 +264,7 @@ def load_legacy_spam_checkers(hs: "synapse.server.HomeServer") -> None:
"""Wrapper that loads spam checkers configured using the old configuration, and
registers the spam checker hooks they implement.
"""
spam_checkers: List[Any] = []
spam_checkers: list[Any] = []
api = hs.get_module_api()
for module, config in hs.config.spamchecker.spam_checkers:
# Older spam checkers don't accept the `api` argument, so we
@@ -312,7 +310,7 @@ def load_legacy_spam_checkers(hs: "synapse.server.HomeServer") -> None:
def wrapper(
email_threepid: Optional[dict],
username: Optional[str],
request_info: Collection[Tuple[str, str]],
request_info: Collection[tuple[str, str]],
auth_provider_id: Optional[str],
) -> Union[Awaitable[RegistrationBehaviour], RegistrationBehaviour]:
# Assertion required because mypy can't prove we won't
@@ -359,36 +357,36 @@ class SpamCheckerModuleApiCallbacks:
self.server_name = hs.hostname
self.clock = hs.get_clock()
self._check_event_for_spam_callbacks: List[CHECK_EVENT_FOR_SPAM_CALLBACK] = []
self._should_drop_federated_event_callbacks: List[
self._check_event_for_spam_callbacks: list[CHECK_EVENT_FOR_SPAM_CALLBACK] = []
self._should_drop_federated_event_callbacks: list[
SHOULD_DROP_FEDERATED_EVENT_CALLBACK
] = []
self._user_may_join_room_callbacks: List[USER_MAY_JOIN_ROOM_CALLBACK] = []
self._user_may_invite_callbacks: List[USER_MAY_INVITE_CALLBACK] = []
self._federated_user_may_invite_callbacks: List[
self._user_may_join_room_callbacks: list[USER_MAY_JOIN_ROOM_CALLBACK] = []
self._user_may_invite_callbacks: list[USER_MAY_INVITE_CALLBACK] = []
self._federated_user_may_invite_callbacks: list[
FEDERATED_USER_MAY_INVITE_CALLBACK
] = []
self._user_may_send_3pid_invite_callbacks: List[
self._user_may_send_3pid_invite_callbacks: list[
USER_MAY_SEND_3PID_INVITE_CALLBACK
] = []
self._user_may_create_room_callbacks: List[USER_MAY_CREATE_ROOM_CALLBACK] = []
self._user_may_send_state_event_callbacks: List[
self._user_may_create_room_callbacks: list[USER_MAY_CREATE_ROOM_CALLBACK] = []
self._user_may_send_state_event_callbacks: list[
USER_MAY_SEND_STATE_EVENT_CALLBACK
] = []
self._user_may_create_room_alias_callbacks: List[
self._user_may_create_room_alias_callbacks: list[
USER_MAY_CREATE_ROOM_ALIAS_CALLBACK
] = []
self._user_may_publish_room_callbacks: List[USER_MAY_PUBLISH_ROOM_CALLBACK] = []
self._check_username_for_spam_callbacks: List[
self._user_may_publish_room_callbacks: list[USER_MAY_PUBLISH_ROOM_CALLBACK] = []
self._check_username_for_spam_callbacks: list[
CHECK_USERNAME_FOR_SPAM_CALLBACK
] = []
self._check_registration_for_spam_callbacks: List[
self._check_registration_for_spam_callbacks: list[
CHECK_REGISTRATION_FOR_SPAM_CALLBACK
] = []
self._check_media_file_for_spam_callbacks: List[
self._check_media_file_for_spam_callbacks: list[
CHECK_MEDIA_FILE_FOR_SPAM_CALLBACK
] = []
self._check_login_for_spam_callbacks: List[CHECK_LOGIN_FOR_SPAM_CALLBACK] = []
self._check_login_for_spam_callbacks: list[CHECK_LOGIN_FOR_SPAM_CALLBACK] = []
def register_callbacks(
self,
@@ -471,7 +469,7 @@ class SpamCheckerModuleApiCallbacks:
@trace
async def check_event_for_spam(
self, event: "synapse.events.EventBase"
) -> Union[Tuple[Codes, JsonDict], str]:
) -> Union[tuple[Codes, JsonDict], str]:
"""Checks if a given event is considered "spammy" by this server.
If the server considers an event spammy, then it will be rejected if
@@ -561,7 +559,7 @@ class SpamCheckerModuleApiCallbacks:
async def user_may_join_room(
self, user_id: str, room_id: str, is_invited: bool
) -> Union[Tuple[Codes, JsonDict], Literal["NOT_SPAM"]]:
) -> Union[tuple[Codes, JsonDict], Literal["NOT_SPAM"]]:
"""Checks if a given users is allowed to join a room.
Not called when a user creates a room.
@@ -605,7 +603,7 @@ class SpamCheckerModuleApiCallbacks:
async def user_may_invite(
self, inviter_userid: str, invitee_userid: str, room_id: str
) -> Union[Tuple[Codes, dict], Literal["NOT_SPAM"]]:
) -> Union[tuple[Codes, dict], Literal["NOT_SPAM"]]:
"""Checks if a given user may send an invite
Args:
@@ -650,7 +648,7 @@ class SpamCheckerModuleApiCallbacks:
async def federated_user_may_invite(
self, event: "synapse.events.EventBase"
) -> Union[Tuple[Codes, dict], Literal["NOT_SPAM"]]:
) -> Union[tuple[Codes, dict], Literal["NOT_SPAM"]]:
"""Checks if a given user may send an invite
Args:
@@ -691,7 +689,7 @@ class SpamCheckerModuleApiCallbacks:
async def user_may_send_3pid_invite(
self, inviter_userid: str, medium: str, address: str, room_id: str
) -> Union[Tuple[Codes, dict], Literal["NOT_SPAM"]]:
) -> Union[tuple[Codes, dict], Literal["NOT_SPAM"]]:
"""Checks if a given user may invite a given threepid into the room
Note that if the threepid is already associated with a Matrix user ID, Synapse
@@ -739,7 +737,7 @@ class SpamCheckerModuleApiCallbacks:
async def user_may_create_room(
self, userid: str, room_config: JsonDict
) -> Union[Tuple[Codes, dict], Literal["NOT_SPAM"]]:
) -> Union[tuple[Codes, dict], Literal["NOT_SPAM"]]:
"""Checks if a given user may create a room
Args:
@@ -805,7 +803,7 @@ class SpamCheckerModuleApiCallbacks:
event_type: str,
state_key: str,
content: JsonDict,
) -> Union[Tuple[Codes, dict], Literal["NOT_SPAM"]]:
) -> Union[tuple[Codes, dict], Literal["NOT_SPAM"]]:
"""Checks if a given user may create a room with a given visibility
Args:
user_id: The ID of the user attempting to create a room
@@ -838,7 +836,7 @@ class SpamCheckerModuleApiCallbacks:
async def user_may_create_room_alias(
self, userid: str, room_alias: RoomAlias
) -> Union[Tuple[Codes, dict], Literal["NOT_SPAM"]]:
) -> Union[tuple[Codes, dict], Literal["NOT_SPAM"]]:
"""Checks if a given user may create a room alias
Args:
@@ -876,7 +874,7 @@ class SpamCheckerModuleApiCallbacks:
async def user_may_publish_room(
self, userid: str, room_id: str
) -> Union[Tuple[Codes, dict], Literal["NOT_SPAM"]]:
) -> Union[tuple[Codes, dict], Literal["NOT_SPAM"]]:
"""Checks if a given user may publish a room to the directory
Args:
@@ -964,7 +962,7 @@ class SpamCheckerModuleApiCallbacks:
self,
email_threepid: Optional[dict],
username: Optional[str],
request_info: Collection[Tuple[str, str]],
request_info: Collection[tuple[str, str]],
auth_provider_id: Optional[str] = None,
) -> RegistrationBehaviour:
"""Checks if we should allow the given registration request.
@@ -1000,7 +998,7 @@ class SpamCheckerModuleApiCallbacks:
@trace
async def check_media_file_for_spam(
self, file_wrapper: ReadableFileWrapper, file_info: FileInfo
) -> Union[Tuple[Codes, dict], Literal["NOT_SPAM"]]:
) -> Union[tuple[Codes, dict], Literal["NOT_SPAM"]]:
"""Checks if a piece of newly uploaded media should be blocked.
This will be called for local uploads, downloads of remote media, each
@@ -1062,9 +1060,9 @@ class SpamCheckerModuleApiCallbacks:
user_id: str,
device_id: Optional[str],
initial_display_name: Optional[str],
request_info: Collection[Tuple[Optional[str], str]],
request_info: Collection[tuple[Optional[str], str]],
auth_provider_id: Optional[str] = None,
) -> Union[Tuple[Codes, dict], Literal["NOT_SPAM"]]:
) -> Union[tuple[Codes, dict], Literal["NOT_SPAM"]]:
"""Checks if we should allow the given registration request.
Args:
@@ -19,7 +19,7 @@
#
#
import logging
from typing import TYPE_CHECKING, Any, Awaitable, Callable, List, Optional, Tuple
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Optional
from twisted.internet.defer import CancelledError
@@ -37,7 +37,7 @@ logger = logging.getLogger(__name__)
CHECK_EVENT_ALLOWED_CALLBACK = Callable[
[EventBase, StateMap[EventBase]], Awaitable[Tuple[bool, Optional[dict]]]
[EventBase, StateMap[EventBase]], Awaitable[tuple[bool, Optional[dict]]]
]
ON_CREATE_ROOM_CALLBACK = Callable[[Requester, dict, bool], Awaitable]
CHECK_THREEPID_CAN_BE_INVITED_CALLBACK = Callable[
@@ -93,7 +93,7 @@ def load_legacy_third_party_event_rules(hs: "HomeServer") -> None:
async def wrap_check_event_allowed(
event: EventBase,
state_events: StateMap[EventBase],
) -> Tuple[bool, Optional[dict]]:
) -> tuple[bool, Optional[dict]]:
# Assertion required because mypy can't prove we won't change
# `f` back to `None`. See
# https://mypy.readthedocs.io/en/latest/common_issues.html#narrowing-and-inner-functions
@@ -159,30 +159,30 @@ class ThirdPartyEventRulesModuleApiCallbacks:
self.store = hs.get_datastores().main
self._storage_controllers = hs.get_storage_controllers()
self._check_event_allowed_callbacks: List[CHECK_EVENT_ALLOWED_CALLBACK] = []
self._on_create_room_callbacks: List[ON_CREATE_ROOM_CALLBACK] = []
self._check_threepid_can_be_invited_callbacks: List[
self._check_event_allowed_callbacks: list[CHECK_EVENT_ALLOWED_CALLBACK] = []
self._on_create_room_callbacks: list[ON_CREATE_ROOM_CALLBACK] = []
self._check_threepid_can_be_invited_callbacks: list[
CHECK_THREEPID_CAN_BE_INVITED_CALLBACK
] = []
self._check_visibility_can_be_modified_callbacks: List[
self._check_visibility_can_be_modified_callbacks: list[
CHECK_VISIBILITY_CAN_BE_MODIFIED_CALLBACK
] = []
self._on_new_event_callbacks: List[ON_NEW_EVENT_CALLBACK] = []
self._check_can_shutdown_room_callbacks: List[
self._on_new_event_callbacks: list[ON_NEW_EVENT_CALLBACK] = []
self._check_can_shutdown_room_callbacks: list[
CHECK_CAN_SHUTDOWN_ROOM_CALLBACK
] = []
self._check_can_deactivate_user_callbacks: List[
self._check_can_deactivate_user_callbacks: list[
CHECK_CAN_DEACTIVATE_USER_CALLBACK
] = []
self._on_profile_update_callbacks: List[ON_PROFILE_UPDATE_CALLBACK] = []
self._on_user_deactivation_status_changed_callbacks: List[
self._on_profile_update_callbacks: list[ON_PROFILE_UPDATE_CALLBACK] = []
self._on_user_deactivation_status_changed_callbacks: list[
ON_USER_DEACTIVATION_STATUS_CHANGED_CALLBACK
] = []
self._on_threepid_bind_callbacks: List[ON_THREEPID_BIND_CALLBACK] = []
self._on_add_user_third_party_identifier_callbacks: List[
self._on_threepid_bind_callbacks: list[ON_THREEPID_BIND_CALLBACK] = []
self._on_add_user_third_party_identifier_callbacks: list[
ON_ADD_USER_THIRD_PARTY_IDENTIFIER_CALLBACK
] = []
self._on_remove_user_third_party_identifier_callbacks: List[
self._on_remove_user_third_party_identifier_callbacks: list[
ON_REMOVE_USER_THIRD_PARTY_IDENTIFIER_CALLBACK
] = []
@@ -261,7 +261,7 @@ class ThirdPartyEventRulesModuleApiCallbacks:
self,
event: EventBase,
context: UnpersistedEventContextBase,
) -> Tuple[bool, Optional[dict]]:
) -> tuple[bool, Optional[dict]]:
"""Check if a provided event should be allowed in the given context.
The module can return: