mirror of
https://github.com/element-hq/synapse.git
synced 2026-08-27 22:34:55 +00:00
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:
@@ -20,7 +20,7 @@
|
||||
#
|
||||
|
||||
import urllib.parse
|
||||
from typing import Dict, cast
|
||||
from typing import cast
|
||||
|
||||
from parameterized import parameterized
|
||||
|
||||
@@ -65,7 +65,7 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
||||
room.register_servlets,
|
||||
]
|
||||
|
||||
def create_resource_dict(self) -> Dict[str, Resource]:
|
||||
def create_resource_dict(self) -> dict[str, Resource]:
|
||||
resources = super().create_resource_dict()
|
||||
resources["/_matrix/media"] = self.hs.get_media_repository_resource()
|
||||
return resources
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
# [This file includes modifications made by New Vector Limited]
|
||||
#
|
||||
#
|
||||
from typing import List
|
||||
|
||||
from twisted.internet.testing import MemoryReactor
|
||||
|
||||
@@ -441,7 +440,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||
)
|
||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||
|
||||
def _check_fields(self, content: List[JsonDict]) -> None:
|
||||
def _check_fields(self, content: list[JsonDict]) -> None:
|
||||
"""Checks that all attributes are present in an event report"""
|
||||
for c in content:
|
||||
self.assertIn("id", c)
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
# [This file includes modifications made by New Vector Limited]
|
||||
#
|
||||
#
|
||||
from typing import List, Optional
|
||||
from typing import Optional
|
||||
|
||||
from parameterized import parameterized
|
||||
|
||||
@@ -272,7 +272,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
|
||||
"""Testing order list with parameter `order_by`"""
|
||||
|
||||
def _order_test(
|
||||
expected_destination_list: List[str],
|
||||
expected_destination_list: list[str],
|
||||
order_by: Optional[str],
|
||||
dir: Optional[str] = None,
|
||||
) -> None:
|
||||
@@ -521,7 +521,7 @@ class FederationTestCase(unittest.HomeserverTestCase):
|
||||
dest = f"sub{i}.example.com"
|
||||
self._create_destination(dest, 50, 50, 50, 100)
|
||||
|
||||
def _check_fields(self, content: List[JsonDict]) -> None:
|
||||
def _check_fields(self, content: list[JsonDict]) -> None:
|
||||
"""Checks that the expected destination attributes are present in content
|
||||
|
||||
Args:
|
||||
@@ -820,7 +820,7 @@ class DestinationMembershipTestCase(unittest.HomeserverTestCase):
|
||||
self,
|
||||
number_rooms: int,
|
||||
destination: Optional[str] = None,
|
||||
) -> List[str]:
|
||||
) -> list[str]:
|
||||
"""
|
||||
Create the given number of rooms. The given `destination` homeserver will
|
||||
be recorded as a participant.
|
||||
@@ -853,7 +853,7 @@ class DestinationMembershipTestCase(unittest.HomeserverTestCase):
|
||||
|
||||
return room_ids
|
||||
|
||||
def _check_fields(self, content: List[JsonDict]) -> None:
|
||||
def _check_fields(self, content: list[JsonDict]) -> None:
|
||||
"""Checks that the expected room attributes are present in content
|
||||
|
||||
Args:
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#
|
||||
#
|
||||
|
||||
from typing import Dict
|
||||
|
||||
from twisted.web.resource import Resource
|
||||
|
||||
@@ -33,7 +32,7 @@ from tests.utils import HAS_AUTHLIB
|
||||
class JWKSTestCase(HomeserverTestCase):
|
||||
"""Test /_synapse/jwks JWKS data."""
|
||||
|
||||
def create_resource_dict(self) -> Dict[str, Resource]:
|
||||
def create_resource_dict(self) -> dict[str, Resource]:
|
||||
d = super().create_resource_dict()
|
||||
d.update(build_synapse_client_resource_tree(self.hs))
|
||||
return d
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#
|
||||
#
|
||||
import os
|
||||
from typing import Dict
|
||||
|
||||
from parameterized import parameterized
|
||||
|
||||
@@ -51,7 +50,7 @@ class _AdminMediaTests(unittest.HomeserverTestCase):
|
||||
media.register_servlets,
|
||||
]
|
||||
|
||||
def create_resource_dict(self) -> Dict[str, Resource]:
|
||||
def create_resource_dict(self) -> dict[str, Resource]:
|
||||
resources = super().create_resource_dict()
|
||||
resources["/_matrix/media"] = self.hs.get_media_repository_resource()
|
||||
return resources
|
||||
|
||||
@@ -22,7 +22,7 @@ import json
|
||||
import time
|
||||
import urllib.parse
|
||||
from http import HTTPStatus
|
||||
from typing import List, Optional
|
||||
from typing import Optional
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
|
||||
from parameterized import parameterized
|
||||
@@ -1609,7 +1609,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||
|
||||
def _order_test(
|
||||
order_type: str,
|
||||
expected_room_list: List[str],
|
||||
expected_room_list: list[str],
|
||||
reverse: bool = False,
|
||||
) -> None:
|
||||
"""Request the list of rooms in a certain order. Assert that order is what
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#
|
||||
#
|
||||
#
|
||||
from typing import Mapping, Optional, Tuple
|
||||
from typing import Mapping, Optional
|
||||
|
||||
from twisted.internet.testing import MemoryReactor
|
||||
|
||||
@@ -42,17 +42,17 @@ class ScheduledTasksAdminApiTestCase(unittest.HomeserverTestCase):
|
||||
# create and schedule a few tasks
|
||||
async def _test_task(
|
||||
task: ScheduledTask,
|
||||
) -> Tuple[TaskStatus, Optional[JsonMapping], Optional[str]]:
|
||||
) -> tuple[TaskStatus, Optional[JsonMapping], Optional[str]]:
|
||||
return TaskStatus.ACTIVE, None, None
|
||||
|
||||
async def _finished_test_task(
|
||||
task: ScheduledTask,
|
||||
) -> Tuple[TaskStatus, Optional[JsonMapping], Optional[str]]:
|
||||
) -> tuple[TaskStatus, Optional[JsonMapping], Optional[str]]:
|
||||
return TaskStatus.COMPLETE, None, None
|
||||
|
||||
async def _failed_test_task(
|
||||
task: ScheduledTask,
|
||||
) -> Tuple[TaskStatus, Optional[JsonMapping], Optional[str]]:
|
||||
) -> tuple[TaskStatus, Optional[JsonMapping], Optional[str]]:
|
||||
return TaskStatus.FAILED, None, "Everything failed"
|
||||
|
||||
self._task_scheduler.register_action(_test_task, "test_task")
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
# [This file includes modifications made by New Vector Limited]
|
||||
#
|
||||
#
|
||||
from typing import List, Sequence
|
||||
from typing import Sequence
|
||||
|
||||
from twisted.internet.testing import MemoryReactor
|
||||
|
||||
@@ -729,7 +729,7 @@ class ServerNoticeTestCase(unittest.HomeserverTestCase):
|
||||
|
||||
return invited_rooms
|
||||
|
||||
def _sync_and_get_messages(self, room_id: str, token: str) -> List[JsonDict]:
|
||||
def _sync_and_get_messages(self, room_id: str, token: str) -> list[JsonDict]:
|
||||
"""
|
||||
Do a sync and get messages of a room.
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
# [This file includes modifications made by New Vector Limited]
|
||||
#
|
||||
#
|
||||
from typing import Dict, List, Optional
|
||||
from typing import Optional
|
||||
|
||||
from twisted.internet.testing import MemoryReactor
|
||||
from twisted.web.resource import Resource
|
||||
@@ -50,7 +50,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||
|
||||
self.url = "/_synapse/admin/v1/statistics/users/media"
|
||||
|
||||
def create_resource_dict(self) -> Dict[str, Resource]:
|
||||
def create_resource_dict(self) -> dict[str, Resource]:
|
||||
resources = super().create_resource_dict()
|
||||
resources["/_matrix/media"] = self.hs.get_media_repository_resource()
|
||||
return resources
|
||||
@@ -485,7 +485,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||
# Upload some media into the room
|
||||
self.helper.upload_media(SMALL_PNG, tok=user_token, expect_code=200)
|
||||
|
||||
def _check_fields(self, content: List[JsonDict]) -> None:
|
||||
def _check_fields(self, content: list[JsonDict]) -> None:
|
||||
"""Checks that all attributes are present in content
|
||||
Args:
|
||||
content: List that is checked for content
|
||||
@@ -497,7 +497,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||
self.assertIn("media_length", c)
|
||||
|
||||
def _order_test(
|
||||
self, order_type: str, expected_user_list: List[str], dir: Optional[str] = None
|
||||
self, order_type: str, expected_user_list: list[str], dir: Optional[str] = None
|
||||
) -> None:
|
||||
"""Request the list of users in a certain order. Assert that order is what
|
||||
we expect
|
||||
|
||||
@@ -27,7 +27,7 @@ import time
|
||||
import urllib.parse
|
||||
from binascii import unhexlify
|
||||
from http import HTTPStatus
|
||||
from typing import Dict, List, Optional
|
||||
from typing import Optional
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
from parameterized import parameterized, parameterized_class
|
||||
@@ -1185,7 +1185,7 @@ class UsersListTestCase(unittest.HomeserverTestCase):
|
||||
)
|
||||
|
||||
def test_user_type(
|
||||
expected_user_ids: List[str], not_user_types: Optional[List[str]] = None
|
||||
expected_user_ids: list[str], not_user_types: Optional[list[str]] = None
|
||||
) -> None:
|
||||
"""Runs a test for the not_user_types param
|
||||
Args:
|
||||
@@ -1262,7 +1262,7 @@ class UsersListTestCase(unittest.HomeserverTestCase):
|
||||
)
|
||||
|
||||
def test_user_type(
|
||||
expected_user_ids: List[str], not_user_types: Optional[List[str]] = None
|
||||
expected_user_ids: list[str], not_user_types: Optional[list[str]] = None
|
||||
) -> None:
|
||||
"""Runs a test for the not_user_types param
|
||||
Args:
|
||||
@@ -1373,7 +1373,7 @@ class UsersListTestCase(unittest.HomeserverTestCase):
|
||||
|
||||
def _order_test(
|
||||
self,
|
||||
expected_user_list: List[str],
|
||||
expected_user_list: list[str],
|
||||
order_by: Optional[str],
|
||||
dir: Optional[str] = None,
|
||||
) -> None:
|
||||
@@ -1403,7 +1403,7 @@ class UsersListTestCase(unittest.HomeserverTestCase):
|
||||
self.assertEqual(expected_user_list, returned_order)
|
||||
self._check_fields(channel.json_body["users"])
|
||||
|
||||
def _check_fields(self, content: List[JsonDict]) -> None:
|
||||
def _check_fields(self, content: list[JsonDict]) -> None:
|
||||
"""Checks that the expected user attributes are present in content
|
||||
Args:
|
||||
content: List that is checked for content
|
||||
@@ -3690,7 +3690,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||
self.other_user
|
||||
)
|
||||
|
||||
def create_resource_dict(self) -> Dict[str, Resource]:
|
||||
def create_resource_dict(self) -> dict[str, Resource]:
|
||||
resources = super().create_resource_dict()
|
||||
resources["/_matrix/media"] = self.hs.get_media_repository_resource()
|
||||
return resources
|
||||
@@ -4138,7 +4138,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||
[media2] + sorted([media1, media3]), "safe_from_quarantine", "b"
|
||||
)
|
||||
|
||||
def _create_media_for_user(self, user_token: str, number_media: int) -> List[str]:
|
||||
def _create_media_for_user(self, user_token: str, number_media: int) -> list[str]:
|
||||
"""
|
||||
Create a number of media for a specific user
|
||||
Args:
|
||||
@@ -4195,7 +4195,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||
|
||||
return media_id
|
||||
|
||||
def _check_fields(self, content: List[JsonDict]) -> None:
|
||||
def _check_fields(self, content: list[JsonDict]) -> None:
|
||||
"""Checks that the expected user attributes are present in content
|
||||
Args:
|
||||
content: List that is checked for content
|
||||
@@ -4212,7 +4212,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||
|
||||
def _order_test(
|
||||
self,
|
||||
expected_media_list: List[str],
|
||||
expected_media_list: list[str],
|
||||
order_by: Optional[str],
|
||||
dir: Optional[str] = None,
|
||||
) -> None:
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#
|
||||
import logging
|
||||
from http import HTTPStatus
|
||||
from typing import List, Optional, Tuple, cast
|
||||
from typing import Optional, cast
|
||||
|
||||
from twisted.test.proto_helpers import MemoryReactor
|
||||
|
||||
@@ -358,7 +358,7 @@ class SlidingSyncThreadSubscriptionsExtensionTestCase(SlidingSyncBase):
|
||||
using the companion /thread_subscriptions endpoint.
|
||||
"""
|
||||
|
||||
thread_root_ids: List[str] = []
|
||||
thread_root_ids: list[str] = []
|
||||
|
||||
def make_subscription() -> None:
|
||||
thread_root_resp = self.helper.send(
|
||||
@@ -455,7 +455,7 @@ class SlidingSyncThreadSubscriptionsExtensionTestCase(SlidingSyncBase):
|
||||
|
||||
def _do_backpaginate(
|
||||
self, *, from_tok: str, to_tok: str, limit: int, access_token: str
|
||||
) -> Tuple[JsonDict, Optional[str]]:
|
||||
) -> tuple[JsonDict, Optional[str]]:
|
||||
channel = self.make_request(
|
||||
"GET",
|
||||
"/_matrix/client/unstable/io.element.msc4308/thread_subscriptions"
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
# <https://www.gnu.org/licenses/agpl-3.0.html>.
|
||||
#
|
||||
import logging
|
||||
from typing import List
|
||||
|
||||
from parameterized import parameterized_class
|
||||
|
||||
@@ -59,7 +58,7 @@ class SlidingSyncToDeviceExtensionTestCase(SlidingSyncBase):
|
||||
super().prepare(reactor, clock, hs)
|
||||
|
||||
def _assert_to_device_response(
|
||||
self, response_body: JsonDict, expected_messages: List[JsonDict]
|
||||
self, response_body: JsonDict, expected_messages: list[JsonDict]
|
||||
) -> str:
|
||||
"""Assert the sliding sync response was successful and has the expected
|
||||
to-device messages.
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
# <https://www.gnu.org/licenses/agpl-3.0.html>.
|
||||
#
|
||||
import logging
|
||||
from typing import List, Optional
|
||||
from typing import Optional
|
||||
|
||||
from parameterized import parameterized_class
|
||||
|
||||
@@ -75,14 +75,14 @@ class SlidingSyncRoomsTimelineTestCase(SlidingSyncBase):
|
||||
if actual_items == expected_items:
|
||||
return
|
||||
|
||||
expected_lines: List[str] = []
|
||||
expected_lines: list[str] = []
|
||||
for expected_item in expected_items:
|
||||
is_expected_in_actual = expected_item in actual_items
|
||||
expected_lines.append(
|
||||
"{} {}".format(" " if is_expected_in_actual else "?", expected_item)
|
||||
)
|
||||
|
||||
actual_lines: List[str] = []
|
||||
actual_lines: list[str] = []
|
||||
for actual_item in actual_items:
|
||||
is_actual_in_expected = actual_item in expected_items
|
||||
actual_lines.append(
|
||||
@@ -101,8 +101,8 @@ class SlidingSyncRoomsTimelineTestCase(SlidingSyncBase):
|
||||
self,
|
||||
*,
|
||||
room_id: str,
|
||||
actual_event_ids: List[str],
|
||||
expected_event_ids: List[str],
|
||||
actual_event_ids: list[str],
|
||||
expected_event_ids: list[str],
|
||||
message: Optional[str] = None,
|
||||
) -> None:
|
||||
"""
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
# <https://www.gnu.org/licenses/agpl-3.0.html>.
|
||||
#
|
||||
import logging
|
||||
from typing import Any, Dict, Iterable, List, Literal, Optional, Tuple
|
||||
from typing import Any, Iterable, Literal, Optional
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from parameterized import parameterized, parameterized_class
|
||||
@@ -82,7 +82,7 @@ class SlidingSyncBase(unittest.HomeserverTestCase):
|
||||
|
||||
def do_sync(
|
||||
self, sync_body: JsonDict, *, since: Optional[str] = None, tok: str
|
||||
) -> Tuple[JsonDict, str]:
|
||||
) -> tuple[JsonDict, str]:
|
||||
"""Do a sliding sync request with given body.
|
||||
|
||||
Asserts the request was successful.
|
||||
@@ -170,7 +170,7 @@ class SlidingSyncBase(unittest.HomeserverTestCase):
|
||||
# Scrutinize the account data since it has no concrete type. We're just copying
|
||||
# everything into a known type. It should be a mapping from user ID to a list of
|
||||
# room IDs. Ignore anything else.
|
||||
new_dm_map: Dict[str, List[str]] = {}
|
||||
new_dm_map: dict[str, list[str]] = {}
|
||||
if isinstance(existing_dm_map, dict):
|
||||
for user_id, room_ids in existing_dm_map.items():
|
||||
if isinstance(user_id, str) and isinstance(room_ids, list):
|
||||
@@ -239,7 +239,7 @@ class SlidingSyncBase(unittest.HomeserverTestCase):
|
||||
def _create_remote_invite_room_for_user(
|
||||
self,
|
||||
invitee_user_id: str,
|
||||
unsigned_invite_room_state: Optional[List[StrippedStateEvent]],
|
||||
unsigned_invite_room_state: Optional[list[StrippedStateEvent]],
|
||||
invite_room_id: Optional[str] = None,
|
||||
) -> str:
|
||||
"""
|
||||
|
||||
@@ -23,7 +23,7 @@ import os
|
||||
import re
|
||||
from email.parser import Parser
|
||||
from http import HTTPStatus
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
from typing import Any, Optional, Union
|
||||
from unittest.mock import Mock
|
||||
|
||||
from twisted.internet.interfaces import IReactorTCP
|
||||
@@ -87,7 +87,7 @@ class PasswordResetTestCase(unittest.HomeserverTestCase):
|
||||
) -> None:
|
||||
self.email_attempts.append(msg_bytes)
|
||||
|
||||
self.email_attempts: List[bytes] = []
|
||||
self.email_attempts: list[bytes] = []
|
||||
hs.get_send_email_handler()._sendmail = sendmail
|
||||
|
||||
return hs
|
||||
@@ -721,7 +721,7 @@ class WhoamiTestCase(unittest.HomeserverTestCase):
|
||||
register.register_servlets,
|
||||
]
|
||||
|
||||
def default_config(self) -> Dict[str, Any]:
|
||||
def default_config(self) -> dict[str, Any]:
|
||||
config = super().default_config()
|
||||
config["allow_guest_access"] = True
|
||||
return config
|
||||
@@ -827,7 +827,7 @@ class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
|
||||
) -> None:
|
||||
self.email_attempts.append(msg_bytes)
|
||||
|
||||
self.email_attempts: List[bytes] = []
|
||||
self.email_attempts: list[bytes] = []
|
||||
self.hs.get_send_email_handler()._sendmail = sendmail
|
||||
|
||||
return self.hs
|
||||
@@ -1501,10 +1501,10 @@ class AccountStatusTestCase(unittest.HomeserverTestCase):
|
||||
|
||||
def _test_status(
|
||||
self,
|
||||
users: Optional[List[str]],
|
||||
users: Optional[list[str]],
|
||||
expected_status_code: int = HTTPStatus.OK,
|
||||
expected_statuses: Optional[Dict[str, Dict[str, bool]]] = None,
|
||||
expected_failures: Optional[List[str]] = None,
|
||||
expected_statuses: Optional[dict[str, dict[str, bool]]] = None,
|
||||
expected_failures: Optional[list[str]] = None,
|
||||
expected_errcode: Optional[str] = None,
|
||||
) -> None:
|
||||
"""Send a request to the account status endpoint and check that the response
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#
|
||||
import re
|
||||
from http import HTTPStatus
|
||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||
from typing import Any, Optional, Union
|
||||
|
||||
from twisted.internet.defer import succeed
|
||||
from twisted.internet.testing import MemoryReactor
|
||||
@@ -47,7 +47,7 @@ from tests.unittest import override_config, skip_unless
|
||||
class DummyRecaptchaChecker(UserInteractiveAuthChecker):
|
||||
def __init__(self, hs: HomeServer) -> None:
|
||||
super().__init__(hs)
|
||||
self.recaptcha_attempts: List[Tuple[dict, str]] = []
|
||||
self.recaptcha_attempts: list[tuple[dict, str]] = []
|
||||
|
||||
def is_enabled(self) -> bool:
|
||||
return True
|
||||
@@ -178,7 +178,7 @@ class UIAuthTests(unittest.HomeserverTestCase):
|
||||
register.register_servlets,
|
||||
]
|
||||
|
||||
def default_config(self) -> Dict[str, Any]:
|
||||
def default_config(self) -> dict[str, Any]:
|
||||
config = super().default_config()
|
||||
|
||||
# public_baseurl uses an http:// scheme because FakeChannel.isSecure() returns
|
||||
@@ -195,7 +195,7 @@ class UIAuthTests(unittest.HomeserverTestCase):
|
||||
|
||||
return config
|
||||
|
||||
def create_resource_dict(self) -> Dict[str, Resource]:
|
||||
def create_resource_dict(self) -> dict[str, Resource]:
|
||||
resource_dict = super().create_resource_dict()
|
||||
resource_dict.update(build_synapse_client_resource_tree(self.hs))
|
||||
return resource_dict
|
||||
@@ -1091,7 +1091,7 @@ class RefreshAuthTests(unittest.HomeserverTestCase):
|
||||
was very slow if a lot of refreshes had been performed for the session.
|
||||
"""
|
||||
|
||||
def _refresh(refresh_token: str) -> Tuple[str, str]:
|
||||
def _refresh(refresh_token: str) -> tuple[str, str]:
|
||||
"""
|
||||
Performs one refresh, returning the next refresh token and access token.
|
||||
"""
|
||||
@@ -1172,7 +1172,7 @@ class RefreshAuthTests(unittest.HomeserverTestCase):
|
||||
|
||||
def oidc_config(
|
||||
id: str, with_localpart_template: bool, **kwargs: Any
|
||||
) -> Dict[str, Any]:
|
||||
) -> dict[str, Any]:
|
||||
"""Sample OIDC provider config used in backchannel logout tests.
|
||||
|
||||
Args:
|
||||
@@ -1185,7 +1185,7 @@ def oidc_config(
|
||||
A dict suitable for the `oidc_config` or the `oidc_providers[]` parts of
|
||||
the HS config
|
||||
"""
|
||||
config: Dict[str, Any] = {
|
||||
config: dict[str, Any] = {
|
||||
"idp_id": id,
|
||||
"idp_name": id,
|
||||
"issuer": TEST_OIDC_ISSUER,
|
||||
@@ -1213,7 +1213,7 @@ class OidcBackchannelLogoutTests(unittest.HomeserverTestCase):
|
||||
login.register_servlets,
|
||||
]
|
||||
|
||||
def default_config(self) -> Dict[str, Any]:
|
||||
def default_config(self) -> dict[str, Any]:
|
||||
config = super().default_config()
|
||||
|
||||
# public_baseurl uses an http:// scheme because FakeChannel.isSecure() returns
|
||||
@@ -1223,7 +1223,7 @@ class OidcBackchannelLogoutTests(unittest.HomeserverTestCase):
|
||||
|
||||
return config
|
||||
|
||||
def create_resource_dict(self) -> Dict[str, Resource]:
|
||||
def create_resource_dict(self) -> dict[str, Resource]:
|
||||
resource_dict = super().create_resource_dict()
|
||||
resource_dict.update(build_synapse_client_resource_tree(self.hs))
|
||||
return resource_dict
|
||||
@@ -1363,7 +1363,7 @@ class OidcBackchannelLogoutTests(unittest.HomeserverTestCase):
|
||||
# We should have a user_mapping_session cookie
|
||||
cookie_headers = channel.headers.getRawHeaders("Set-Cookie")
|
||||
assert cookie_headers
|
||||
cookies: Dict[str, str] = {}
|
||||
cookies: dict[str, str] = {}
|
||||
for h in cookie_headers:
|
||||
key, value = h.split(";")[0].split("=", maxsplit=1)
|
||||
cookies[key] = value
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
"""Tests REST events for /delayed_events paths."""
|
||||
|
||||
from http import HTTPStatus
|
||||
from typing import List
|
||||
|
||||
from parameterized import parameterized
|
||||
|
||||
@@ -574,7 +573,7 @@ class DelayedEventsTestCase(HomeserverTestCase):
|
||||
)
|
||||
self.assertEqual(setter_expected, content.get(setter_key), content)
|
||||
|
||||
def _get_delayed_events(self) -> List[JsonDict]:
|
||||
def _get_delayed_events(self) -> list[JsonDict]:
|
||||
channel = self.make_request(
|
||||
"GET",
|
||||
PATH_PREFIX,
|
||||
|
||||
@@ -25,11 +25,8 @@ from typing import (
|
||||
BinaryIO,
|
||||
Callable,
|
||||
Collection,
|
||||
Dict,
|
||||
List,
|
||||
Literal,
|
||||
Optional,
|
||||
Tuple,
|
||||
Union,
|
||||
)
|
||||
from unittest.mock import Mock
|
||||
@@ -146,11 +143,11 @@ class TestSpamChecker:
|
||||
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[
|
||||
Literal["NOT_SPAM"],
|
||||
Tuple["synapse.module_api.errors.Codes", JsonDict],
|
||||
tuple["synapse.module_api.errors.Codes", JsonDict],
|
||||
]:
|
||||
return "NOT_SPAM"
|
||||
|
||||
@@ -170,11 +167,11 @@ class DenyAllSpamChecker:
|
||||
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[
|
||||
Literal["NOT_SPAM"],
|
||||
Tuple["synapse.module_api.errors.Codes", JsonDict],
|
||||
tuple["synapse.module_api.errors.Codes", JsonDict],
|
||||
]:
|
||||
# Return an odd set of values to ensure that they get correctly passed
|
||||
# to the client.
|
||||
@@ -633,7 +630,7 @@ class MultiSSOTestCase(unittest.HomeserverTestCase):
|
||||
login.register_servlets,
|
||||
]
|
||||
|
||||
def default_config(self) -> Dict[str, Any]:
|
||||
def default_config(self) -> dict[str, Any]:
|
||||
config = super().default_config()
|
||||
|
||||
config["public_baseurl"] = PUBLIC_BASEURL
|
||||
@@ -678,7 +675,7 @@ class MultiSSOTestCase(unittest.HomeserverTestCase):
|
||||
def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
|
||||
self.login_sso_redirect_url_builder = LoginSSORedirectURIBuilder(hs.config)
|
||||
|
||||
def create_resource_dict(self) -> Dict[str, Resource]:
|
||||
def create_resource_dict(self) -> dict[str, Resource]:
|
||||
d = super().create_resource_dict()
|
||||
d.update(build_synapse_client_resource_tree(self.hs))
|
||||
return d
|
||||
@@ -730,7 +727,7 @@ class MultiSSOTestCase(unittest.HomeserverTestCase):
|
||||
p.close()
|
||||
|
||||
# there should be a link for each href
|
||||
returned_idps: List[str] = []
|
||||
returned_idps: list[str] = []
|
||||
for link in p.links:
|
||||
path, query = link.split("?", 1)
|
||||
self.assertEqual(path, "pick_idp")
|
||||
@@ -891,7 +888,7 @@ class MultiSSOTestCase(unittest.HomeserverTestCase):
|
||||
# ... and should have set a cookie including the redirect url
|
||||
cookie_headers = channel.headers.getRawHeaders("Set-Cookie")
|
||||
assert cookie_headers
|
||||
cookies: Dict[str, str] = {}
|
||||
cookies: dict[str, str] = {}
|
||||
for h in cookie_headers:
|
||||
key, value = h.split(";")[0].split("=", maxsplit=1)
|
||||
cookies[key] = value
|
||||
@@ -1179,7 +1176,7 @@ class JWTTestCase(unittest.HomeserverTestCase):
|
||||
"algorithm": jwt_algorithm,
|
||||
}
|
||||
|
||||
def default_config(self) -> Dict[str, Any]:
|
||||
def default_config(self) -> dict[str, Any]:
|
||||
config = super().default_config()
|
||||
|
||||
# If jwt_config has been defined (eg via @override_config), don't replace it.
|
||||
@@ -1188,7 +1185,7 @@ class JWTTestCase(unittest.HomeserverTestCase):
|
||||
|
||||
return config
|
||||
|
||||
def jwt_encode(self, payload: Dict[str, Any], secret: str = jwt_secret) -> str:
|
||||
def jwt_encode(self, payload: dict[str, Any], secret: str = jwt_secret) -> str:
|
||||
header = {"alg": self.jwt_algorithm}
|
||||
result: bytes = jwt.encode(header, payload, secret)
|
||||
return result.decode("ascii")
|
||||
@@ -1426,7 +1423,7 @@ class JWTPubKeyTestCase(unittest.HomeserverTestCase):
|
||||
]
|
||||
)
|
||||
|
||||
def default_config(self) -> Dict[str, Any]:
|
||||
def default_config(self) -> dict[str, Any]:
|
||||
config = super().default_config()
|
||||
config["jwt_config"] = {
|
||||
"enabled": True,
|
||||
@@ -1435,7 +1432,7 @@ class JWTPubKeyTestCase(unittest.HomeserverTestCase):
|
||||
}
|
||||
return config
|
||||
|
||||
def jwt_encode(self, payload: Dict[str, Any], secret: str = jwt_privatekey) -> str:
|
||||
def jwt_encode(self, payload: dict[str, Any], secret: str = jwt_privatekey) -> str:
|
||||
header = {"alg": "RS256"}
|
||||
if secret.startswith("-----BEGIN RSA PRIVATE KEY-----"):
|
||||
secret = JsonWebKey.import_key(secret, {"kty": "RSA"})
|
||||
@@ -1630,7 +1627,7 @@ class UsernamePickerTestCase(HomeserverTestCase):
|
||||
)
|
||||
return hs
|
||||
|
||||
def default_config(self) -> Dict[str, Any]:
|
||||
def default_config(self) -> dict[str, Any]:
|
||||
config = super().default_config()
|
||||
config["public_baseurl"] = PUBLIC_BASEURL
|
||||
|
||||
@@ -1649,7 +1646,7 @@ class UsernamePickerTestCase(HomeserverTestCase):
|
||||
config["sso"] = {"client_whitelist": ["https://x"]}
|
||||
return config
|
||||
|
||||
def create_resource_dict(self) -> Dict[str, Resource]:
|
||||
def create_resource_dict(self) -> dict[str, Resource]:
|
||||
d = super().create_resource_dict()
|
||||
d.update(build_synapse_client_resource_tree(self.hs))
|
||||
return d
|
||||
@@ -1660,7 +1657,7 @@ class UsernamePickerTestCase(HomeserverTestCase):
|
||||
displayname: str,
|
||||
email: str,
|
||||
picture: str,
|
||||
) -> Tuple[str, str]:
|
||||
) -> tuple[str, str]:
|
||||
# do the start of the login flow
|
||||
channel, _ = self.helper.auth_via_oidc(
|
||||
fake_oidc_server,
|
||||
@@ -1681,7 +1678,7 @@ class UsernamePickerTestCase(HomeserverTestCase):
|
||||
self.assertEqual(picker_url, "/_synapse/client/pick_username/account_details")
|
||||
|
||||
# ... with a username_mapping_session cookie
|
||||
cookies: Dict[str, str] = {}
|
||||
cookies: dict[str, str] = {}
|
||||
channel.extract_cookies(cookies)
|
||||
self.assertIn("username_mapping_session", cookies)
|
||||
session_id = cookies["username_mapping_session"]
|
||||
@@ -1894,5 +1891,5 @@ async def mock_get_file(
|
||||
max_size: Optional[int] = None,
|
||||
headers: Optional[RawHeaders] = None,
|
||||
is_allowed_content_type: Optional[Callable[[str], bool]] = None,
|
||||
) -> Tuple[int, Dict[bytes, List[bytes]], str, int]:
|
||||
) -> tuple[int, dict[bytes, list[bytes]], str, int]:
|
||||
return 0, {b"Content-Type": [b"image/png"]}, "", 200
|
||||
|
||||
@@ -24,7 +24,7 @@ import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
from typing import Any, BinaryIO, ClassVar, Dict, List, Optional, Sequence, Tuple, Type
|
||||
from typing import Any, BinaryIO, ClassVar, Optional, Sequence
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
from urllib import parse
|
||||
from urllib.parse import quote, urlencode
|
||||
@@ -265,7 +265,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||
assert self.media_repo.url_previewer is not None
|
||||
self.url_previewer = self.media_repo.url_previewer
|
||||
|
||||
self.lookups: Dict[str, Any] = {}
|
||||
self.lookups: dict[str, Any] = {}
|
||||
|
||||
class Resolver:
|
||||
def resolveHostName(
|
||||
@@ -273,7 +273,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||
resolutionReceiver: IResolutionReceiver,
|
||||
hostName: str,
|
||||
portNumber: int = 0,
|
||||
addressTypes: Optional[Sequence[Type[IAddress]]] = None,
|
||||
addressTypes: Optional[Sequence[type[IAddress]]] = None,
|
||||
transportSemantics: str = "TCP",
|
||||
) -> IResolutionReceiver:
|
||||
resolution = HostResolution(hostName)
|
||||
@@ -1357,7 +1357,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||
self.assertEqual(body["og:title"], "Test")
|
||||
self.assertNotIn("og:image", body)
|
||||
|
||||
def _download_image(self) -> Tuple[str, str]:
|
||||
def _download_image(self) -> tuple[str, str]:
|
||||
"""Downloads an image into the URL cache.
|
||||
Returns:
|
||||
A (host, media_id) tuple representing the MXC URI of the image.
|
||||
@@ -1994,8 +1994,8 @@ class DownloadAndThumbnailTestCase(unittest.HomeserverTestCase):
|
||||
]
|
||||
|
||||
def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
|
||||
self.fetches: List[
|
||||
Tuple[
|
||||
self.fetches: list[
|
||||
tuple[
|
||||
"Deferred[Any]",
|
||||
str,
|
||||
str,
|
||||
@@ -2014,12 +2014,12 @@ class DownloadAndThumbnailTestCase(unittest.HomeserverTestCase):
|
||||
retry_on_dns_fail: bool = True,
|
||||
ignore_backoff: bool = False,
|
||||
follow_redirects: bool = False,
|
||||
) -> "Deferred[Tuple[int, Dict[bytes, List[bytes]], bytes]]":
|
||||
) -> "Deferred[tuple[int, dict[bytes, list[bytes]], bytes]]":
|
||||
"""A mock for MatrixFederationHttpClient.federation_get_file."""
|
||||
|
||||
def write_to(
|
||||
r: Tuple[bytes, Tuple[int, Dict[bytes, List[bytes]], bytes]],
|
||||
) -> Tuple[int, Dict[bytes, List[bytes]], bytes]:
|
||||
r: tuple[bytes, tuple[int, dict[bytes, list[bytes]], bytes]],
|
||||
) -> tuple[int, dict[bytes, list[bytes]], bytes]:
|
||||
data, response = r
|
||||
output_stream.write(data)
|
||||
return response
|
||||
@@ -2029,7 +2029,7 @@ class DownloadAndThumbnailTestCase(unittest.HomeserverTestCase):
|
||||
output_stream.write(f.value.response)
|
||||
return f
|
||||
|
||||
d: Deferred[Tuple[bytes, Tuple[int, Dict[bytes, List[bytes]], bytes]]] = (
|
||||
d: Deferred[tuple[bytes, tuple[int, dict[bytes, list[bytes]], bytes]]] = (
|
||||
Deferred()
|
||||
)
|
||||
self.fetches.append((d, destination, path, args))
|
||||
@@ -2048,12 +2048,12 @@ class DownloadAndThumbnailTestCase(unittest.HomeserverTestCase):
|
||||
retry_on_dns_fail: bool = True,
|
||||
ignore_backoff: bool = False,
|
||||
follow_redirects: bool = False,
|
||||
) -> "Deferred[Tuple[int, Dict[bytes, List[bytes]]]]":
|
||||
) -> "Deferred[tuple[int, dict[bytes, list[bytes]]]]":
|
||||
"""A mock for MatrixFederationHttpClient.get_file."""
|
||||
|
||||
def write_to(
|
||||
r: Tuple[bytes, Tuple[int, Dict[bytes, List[bytes]]]],
|
||||
) -> Tuple[int, Dict[bytes, List[bytes]]]:
|
||||
r: tuple[bytes, tuple[int, dict[bytes, list[bytes]]]],
|
||||
) -> tuple[int, dict[bytes, list[bytes]]]:
|
||||
data, response = r
|
||||
output_stream.write(data)
|
||||
return response
|
||||
@@ -2063,7 +2063,7 @@ class DownloadAndThumbnailTestCase(unittest.HomeserverTestCase):
|
||||
output_stream.write(f.value.response)
|
||||
return f
|
||||
|
||||
d: Deferred[Tuple[bytes, Tuple[int, Dict[bytes, List[bytes]]]]] = Deferred()
|
||||
d: Deferred[tuple[bytes, tuple[int, dict[bytes, list[bytes]]]]] = Deferred()
|
||||
self.fetches.append((d, destination, path, args))
|
||||
# Note that this callback changes the value held by d.
|
||||
d_after_callback = d.addCallbacks(write_to, write_err)
|
||||
@@ -2538,7 +2538,7 @@ configs = [
|
||||
|
||||
@parameterized_class(configs)
|
||||
class AuthenticatedMediaTestCase(unittest.HomeserverTestCase):
|
||||
extra_config: Dict[str, Any]
|
||||
extra_config: dict[str, Any]
|
||||
servlets = [
|
||||
media.register_servlets,
|
||||
login.register_servlets,
|
||||
@@ -2576,7 +2576,7 @@ class AuthenticatedMediaTestCase(unittest.HomeserverTestCase):
|
||||
self.user = self.register_user("user", "pass")
|
||||
self.tok = self.login("user", "pass")
|
||||
|
||||
def create_resource_dict(self) -> Dict[str, Resource]:
|
||||
def create_resource_dict(self) -> dict[str, Resource]:
|
||||
resources = super().create_resource_dict()
|
||||
resources["/_matrix/media"] = self.hs.get_media_repository_resource()
|
||||
return resources
|
||||
@@ -2895,7 +2895,7 @@ class MediaUploadLimits(unittest.HomeserverTestCase):
|
||||
self.user = self.register_user("user", "pass")
|
||||
self.tok = self.login("user", "pass")
|
||||
|
||||
def create_resource_dict(self) -> Dict[str, Resource]:
|
||||
def create_resource_dict(self) -> dict[str, Resource]:
|
||||
resources = super().create_resource_dict()
|
||||
resources["/_matrix/media"] = self.hs.get_media_repository_resource()
|
||||
return resources
|
||||
@@ -3012,7 +3012,7 @@ class MediaUploadLimitsModuleOverrides(unittest.HomeserverTestCase):
|
||||
async def _get_media_upload_limits_for_user(
|
||||
self,
|
||||
user_id: str,
|
||||
) -> Optional[List[MediaUploadLimit]]:
|
||||
) -> Optional[list[MediaUploadLimit]]:
|
||||
# user1 has custom limits
|
||||
if user_id == self.user1:
|
||||
# n.b. we return these in increasing duration order and Synapse will need to sort them correctly
|
||||
@@ -3060,7 +3060,7 @@ class MediaUploadLimitsModuleOverrides(unittest.HomeserverTestCase):
|
||||
on_media_upload_limit_exceeded=self._on_media_upload_limit_exceeded,
|
||||
)
|
||||
|
||||
def create_resource_dict(self) -> Dict[str, Resource]:
|
||||
def create_resource_dict(self) -> dict[str, Resource]:
|
||||
resources = super().create_resource_dict()
|
||||
resources["/_matrix/media"] = self.hs.get_media_repository_resource()
|
||||
return resources
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
# [This file includes modifications made by New Vector Limited]
|
||||
#
|
||||
#
|
||||
from typing import List, Optional, Tuple
|
||||
from typing import Optional
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
|
||||
from twisted.internet.testing import MemoryReactor
|
||||
@@ -156,7 +156,7 @@ class HTTPPusherTests(HomeserverTestCase):
|
||||
|
||||
def _request_notifications(
|
||||
self, from_token: Optional[str], limit: int, expected_count: int
|
||||
) -> Tuple[List[str], str]:
|
||||
) -> tuple[list[str], str]:
|
||||
"""
|
||||
Make a request to /notifications to get the latest events to be notified about.
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
import logging
|
||||
import urllib.parse
|
||||
from http import HTTPStatus
|
||||
from typing import Any, Dict, Optional
|
||||
from typing import Any, Optional
|
||||
|
||||
from canonicaljson import encode_canonical_json
|
||||
|
||||
@@ -778,7 +778,7 @@ class ProfileTestCase(unittest.HomeserverTestCase):
|
||||
self.assertEqual(channel.code, 403, channel.result)
|
||||
self.assertEqual(channel.json_body["errcode"], Codes.FORBIDDEN)
|
||||
|
||||
def _setup_local_files(self, names_and_props: Dict[str, Dict[str, Any]]) -> None:
|
||||
def _setup_local_files(self, names_and_props: dict[str, dict[str, Any]]) -> None:
|
||||
"""Stores metadata about files in the database.
|
||||
|
||||
Args:
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
# [This file includes modifications made by New Vector Limited]
|
||||
#
|
||||
#
|
||||
from typing import List, Optional
|
||||
from typing import Optional
|
||||
|
||||
from parameterized import parameterized
|
||||
|
||||
@@ -85,7 +85,7 @@ class RedactionsTestCase(HomeserverTestCase):
|
||||
room_id: str,
|
||||
event_id: str,
|
||||
expect_code: int = 200,
|
||||
with_relations: Optional[List[str]] = None,
|
||||
with_relations: Optional[list[str]] = None,
|
||||
content: Optional[JsonDict] = None,
|
||||
) -> JsonDict:
|
||||
"""Helper function to send a redaction event.
|
||||
@@ -104,7 +104,7 @@ class RedactionsTestCase(HomeserverTestCase):
|
||||
self.assertEqual(channel.code, expect_code)
|
||||
return channel.json_body
|
||||
|
||||
def _sync_room_timeline(self, access_token: str, room_id: str) -> List[JsonDict]:
|
||||
def _sync_room_timeline(self, access_token: str, room_id: str) -> list[JsonDict]:
|
||||
channel = self.make_request("GET", "sync", access_token=access_token)
|
||||
self.assertEqual(channel.code, 200)
|
||||
room_sync = channel.json_body["rooms"]["join"][room_id]
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
import datetime
|
||||
import importlib.resources as importlib_resources
|
||||
import os
|
||||
from typing import Any, Dict, List, Tuple
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from twisted.internet.testing import MemoryReactor
|
||||
@@ -54,7 +54,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
||||
]
|
||||
url = b"/_matrix/client/r0/register"
|
||||
|
||||
def default_config(self) -> Dict[str, Any]:
|
||||
def default_config(self) -> dict[str, Any]:
|
||||
config = super().default_config()
|
||||
config["allow_guest_access"] = True
|
||||
return config
|
||||
@@ -1032,7 +1032,7 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
|
||||
async def sendmail(*args: Any, **kwargs: Any) -> None:
|
||||
self.email_attempts.append((args, kwargs))
|
||||
|
||||
self.email_attempts: List[Tuple[Any, Any]] = []
|
||||
self.email_attempts: list[tuple[Any, Any]] = []
|
||||
self.hs.get_send_email_handler()._sendmail = sendmail
|
||||
|
||||
self.store = self.hs.get_datastores().main
|
||||
@@ -1146,7 +1146,7 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
|
||||
|
||||
self.assertEqual(len(self.email_attempts), 0)
|
||||
|
||||
def create_user(self) -> Tuple[str, str]:
|
||||
def create_user(self) -> tuple[str, str]:
|
||||
user_id = self.register_user("kermit", "monkey")
|
||||
tok = self.login("kermit", "monkey")
|
||||
# We need to manually add an email address otherwise the handler will do
|
||||
@@ -1250,7 +1250,7 @@ class RegistrationTokenValidityRestServletTestCase(unittest.HomeserverTestCase):
|
||||
servlets = [register.register_servlets]
|
||||
url = "/_matrix/client/v1/register/m.login.registration_token/validity"
|
||||
|
||||
def default_config(self) -> Dict[str, Any]:
|
||||
def default_config(self) -> dict[str, Any]:
|
||||
config = super().default_config()
|
||||
config["registration_requires_token"] = True
|
||||
return config
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#
|
||||
|
||||
import urllib.parse
|
||||
from typing import Any, Callable, Dict, List, Optional, Tuple
|
||||
from typing import Any, Callable, Optional
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from twisted.internet.testing import MemoryReactor
|
||||
@@ -48,7 +48,7 @@ class BaseRelationsTestCase(unittest.HomeserverTestCase):
|
||||
]
|
||||
hijack_auth = False
|
||||
|
||||
def default_config(self) -> Dict[str, Any]:
|
||||
def default_config(self) -> dict[str, Any]:
|
||||
# We need to enable msc1849 support for aggregations
|
||||
config = super().default_config()
|
||||
|
||||
@@ -69,7 +69,7 @@ class BaseRelationsTestCase(unittest.HomeserverTestCase):
|
||||
res = self.helper.send(self.room, body="Hi!", tok=self.user_token)
|
||||
self.parent_id = res["event_id"]
|
||||
|
||||
def _create_user(self, localpart: str) -> Tuple[str, str]:
|
||||
def _create_user(self, localpart: str) -> tuple[str, str]:
|
||||
user_id = self.register_user(localpart, "abc123")
|
||||
access_token = self.login(localpart, "abc123")
|
||||
|
||||
@@ -123,7 +123,7 @@ class BaseRelationsTestCase(unittest.HomeserverTestCase):
|
||||
self.assertEqual(expected_response_code, channel.code, channel.json_body)
|
||||
return channel
|
||||
|
||||
def _get_related_events(self) -> List[str]:
|
||||
def _get_related_events(self) -> list[str]:
|
||||
"""
|
||||
Requests /relations on the parent ID and returns a list of event IDs.
|
||||
"""
|
||||
@@ -149,7 +149,7 @@ class BaseRelationsTestCase(unittest.HomeserverTestCase):
|
||||
self.assertEqual(200, channel.code, channel.json_body)
|
||||
return channel.json_body["unsigned"].get("m.relations", {})
|
||||
|
||||
def _find_event_in_chunk(self, events: List[JsonDict]) -> JsonDict:
|
||||
def _find_event_in_chunk(self, events: list[JsonDict]) -> JsonDict:
|
||||
"""
|
||||
Find the parent event in a chunk of events and assert that it has the proper bundled aggregations.
|
||||
"""
|
||||
@@ -846,7 +846,7 @@ class RelationPaginationTestCase(BaseRelationsTestCase):
|
||||
expected_event_ids.append(channel.json_body["event_id"])
|
||||
|
||||
prev_token: Optional[str] = ""
|
||||
found_event_ids: List[str] = []
|
||||
found_event_ids: list[str] = []
|
||||
for _ in range(20):
|
||||
from_token = ""
|
||||
if prev_token:
|
||||
@@ -1484,9 +1484,9 @@ class RelationIgnoredUserTestCase(BaseRelationsTestCase):
|
||||
def _test_ignored_user(
|
||||
self,
|
||||
relation_type: str,
|
||||
allowed_event_ids: List[str],
|
||||
ignored_event_ids: List[str],
|
||||
) -> Tuple[JsonDict, JsonDict]:
|
||||
allowed_event_ids: list[str],
|
||||
ignored_event_ids: list[str],
|
||||
) -> tuple[JsonDict, JsonDict]:
|
||||
"""
|
||||
Fetch the relations and ensure they're all there, then ignore user2, and
|
||||
repeat.
|
||||
@@ -1600,7 +1600,7 @@ class RelationRedactionTestCase(BaseRelationsTestCase):
|
||||
)
|
||||
self.assertEqual(200, channel.code, channel.json_body)
|
||||
|
||||
def _get_threads(self) -> List[Tuple[str, str]]:
|
||||
def _get_threads(self) -> list[tuple[str, str]]:
|
||||
"""Request the threads in the room and returns a list of thread ID and latest event ID."""
|
||||
# Request the threads in the room.
|
||||
channel = self.make_request(
|
||||
@@ -1793,7 +1793,7 @@ class RelationRedactionTestCase(BaseRelationsTestCase):
|
||||
|
||||
|
||||
class ThreadsTestCase(BaseRelationsTestCase):
|
||||
def _get_threads(self, body: JsonDict) -> List[Tuple[str, str]]:
|
||||
def _get_threads(self, body: JsonDict) -> list[tuple[str, str]]:
|
||||
return [
|
||||
(
|
||||
ev["event_id"],
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#
|
||||
#
|
||||
|
||||
from typing import Dict
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from twisted.internet.testing import MemoryReactor
|
||||
@@ -46,7 +45,7 @@ class RendezvousServletTestCase(unittest.HomeserverTestCase):
|
||||
self.hs = self.setup_test_homeserver()
|
||||
return self.hs
|
||||
|
||||
def create_resource_dict(self) -> Dict[str, Resource]:
|
||||
def create_resource_dict(self) -> dict[str, Resource]:
|
||||
return {
|
||||
**super().create_resource_dict(),
|
||||
"/_synapse/client/rendezvous": MSC4108RendezvousSessionResource(self.hs),
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# [This file includes modifications made by New Vector Limited]
|
||||
#
|
||||
#
|
||||
from typing import Any, Dict
|
||||
from typing import Any
|
||||
from unittest.mock import Mock
|
||||
|
||||
from twisted.internet.testing import MemoryReactor
|
||||
@@ -265,7 +265,7 @@ class RetentionNoDefaultPolicyTestCase(unittest.HomeserverTestCase):
|
||||
room.register_servlets,
|
||||
]
|
||||
|
||||
def default_config(self) -> Dict[str, Any]:
|
||||
def default_config(self) -> dict[str, Any]:
|
||||
config = super().default_config()
|
||||
|
||||
retention_config = {
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
import json
|
||||
from http import HTTPStatus
|
||||
from typing import Any, Dict, Iterable, List, Literal, Optional, Tuple, Union
|
||||
from typing import Any, Iterable, Literal, Optional, Union
|
||||
from unittest.mock import AsyncMock, Mock, call, patch
|
||||
from urllib import parse as urlparse
|
||||
|
||||
@@ -989,7 +989,7 @@ class RoomsCreateTestCase(RoomBase):
|
||||
mxid: str,
|
||||
room_id: str,
|
||||
is_invite: bool,
|
||||
) -> Tuple[Codes, dict]:
|
||||
) -> tuple[Codes, dict]:
|
||||
return Codes.INCOMPATIBLE_ROOM_VERSION, {}
|
||||
|
||||
join_mock.side_effect = user_may_join_room_tuple
|
||||
@@ -1002,7 +1002,7 @@ class RoomsCreateTestCase(RoomBase):
|
||||
self.assertEqual(channel.code, HTTPStatus.OK, channel.json_body)
|
||||
self.assertEqual(join_mock.call_count, 0)
|
||||
|
||||
def _create_basic_room(self) -> Tuple[int, object]:
|
||||
def _create_basic_room(self) -> tuple[int, object]:
|
||||
"""
|
||||
Tries to create a basic room and returns the response code.
|
||||
"""
|
||||
@@ -1351,7 +1351,7 @@ class RoomJoinTestCase(RoomBase):
|
||||
"""
|
||||
|
||||
# Register a dummy callback. Make it allow all room joins for now.
|
||||
return_value: Union[Literal["NOT_SPAM"], Tuple[Codes, dict], Codes] = (
|
||||
return_value: Union[Literal["NOT_SPAM"], tuple[Codes, dict], Codes] = (
|
||||
synapse.module_api.NOT_SPAM
|
||||
)
|
||||
|
||||
@@ -1359,7 +1359,7 @@ class RoomJoinTestCase(RoomBase):
|
||||
userid: str,
|
||||
room_id: str,
|
||||
is_invited: bool,
|
||||
) -> Union[Literal["NOT_SPAM"], Tuple[Codes, dict], Codes]:
|
||||
) -> Union[Literal["NOT_SPAM"], tuple[Codes, dict], Codes]:
|
||||
return return_value
|
||||
|
||||
# `spec` argument is needed for this function mock to have `__qualname__`, which
|
||||
@@ -1848,12 +1848,12 @@ class RoomMessagesTestCase(RoomBase):
|
||||
def test_spam_checker_check_event_for_spam(
|
||||
self,
|
||||
name: str,
|
||||
value: Union[str, bool, Codes, Tuple[Codes, JsonDict]],
|
||||
value: Union[str, bool, Codes, tuple[Codes, JsonDict]],
|
||||
expected_code: int,
|
||||
expected_fields: dict,
|
||||
) -> None:
|
||||
class SpamCheck:
|
||||
mock_return_value: Union[str, bool, Codes, Tuple[Codes, JsonDict], bool] = (
|
||||
mock_return_value: Union[str, bool, Codes, tuple[Codes, JsonDict], bool] = (
|
||||
"NOT_SPAM"
|
||||
)
|
||||
mock_content: Optional[JsonDict] = None
|
||||
@@ -1861,7 +1861,7 @@ class RoomMessagesTestCase(RoomBase):
|
||||
async def check_event_for_spam(
|
||||
self,
|
||||
event: synapse.events.EventBase,
|
||||
) -> Union[str, Codes, Tuple[Codes, JsonDict], bool]:
|
||||
) -> Union[str, Codes, tuple[Codes, JsonDict], bool]:
|
||||
self.mock_content = event.content
|
||||
return self.mock_return_value
|
||||
|
||||
@@ -1915,7 +1915,7 @@ class RoomPowerLevelOverridesTestCase(RoomBase):
|
||||
self.admin_user_id = self.register_user("admin", "pass")
|
||||
self.admin_access_token = self.login("admin", "pass")
|
||||
|
||||
def power_levels(self, room_id: str) -> Dict[str, Any]:
|
||||
def power_levels(self, room_id: str) -> dict[str, Any]:
|
||||
return self.helper.get_state(
|
||||
room_id, "m.room.power_levels", self.admin_access_token
|
||||
)
|
||||
@@ -2076,7 +2076,7 @@ class RoomPowerLevelOverridesInPracticeTestCase(RoomBase):
|
||||
# Given the server has config allowing normal users to post my event type
|
||||
# And I am a normal member of a room
|
||||
# But the room was created with special permissions
|
||||
extra_content: Dict[str, Any] = {
|
||||
extra_content: dict[str, Any] = {
|
||||
"power_level_content_override": {"events": {}},
|
||||
}
|
||||
room_id = self.helper.create_room_as(
|
||||
@@ -2707,9 +2707,9 @@ class PublicRoomsRoomTypeFilterTestCase(unittest.HomeserverTestCase):
|
||||
|
||||
def make_public_rooms_request(
|
||||
self,
|
||||
room_types: Optional[List[Union[str, None]]],
|
||||
room_types: Optional[list[Union[str, None]]],
|
||||
instance_id: Optional[str] = None,
|
||||
) -> Tuple[List[Dict[str, Any]], int]:
|
||||
) -> tuple[list[dict[str, Any]], int]:
|
||||
body: JsonDict = {"filter": {PublicRoomsFilterFields.ROOM_TYPES: room_types}}
|
||||
if instance_id:
|
||||
body["third_party_instance_id"] = "test|test"
|
||||
@@ -3470,7 +3470,7 @@ class LabelsTestCase(unittest.HomeserverTestCase):
|
||||
|
||||
|
||||
class RelationsTestCase(PaginationTestCase):
|
||||
def _filter_messages(self, filter: JsonDict) -> List[str]:
|
||||
def _filter_messages(self, filter: JsonDict) -> list[str]:
|
||||
"""Make a request to /messages with a filter, returns the chunk of events."""
|
||||
from_token = self.get_success(
|
||||
self.from_token.to_string(self.hs.get_datastores().main)
|
||||
@@ -4529,8 +4529,8 @@ class MSC4293RedactOnBanKickTestCase(unittest.FederatingHomeserverTestCase):
|
||||
|
||||
def _check_redactions(
|
||||
self,
|
||||
original_events: List[EventBase],
|
||||
pulled_events: List[JsonDict],
|
||||
original_events: list[EventBase],
|
||||
pulled_events: list[JsonDict],
|
||||
expect_redaction: bool,
|
||||
reason: Optional[str] = None,
|
||||
) -> None:
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#
|
||||
import json
|
||||
import logging
|
||||
from typing import List
|
||||
|
||||
from parameterized import parameterized
|
||||
|
||||
@@ -131,7 +130,7 @@ class SyncFilterTestCase(unittest.HomeserverTestCase):
|
||||
self.assertEqual(len(events), 1, [event["content"] for event in events])
|
||||
self.assertEqual(events[0]["content"]["body"], "with wrong label", events[0])
|
||||
|
||||
def _test_sync_filter_labels(self, sync_filter: str) -> List[JsonDict]:
|
||||
def _test_sync_filter_labels(self, sync_filter: str) -> list[JsonDict]:
|
||||
user_id = self.register_user("kermit", "test")
|
||||
tok = self.login("kermit", "test")
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#
|
||||
#
|
||||
import threading
|
||||
from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, Union
|
||||
from typing import TYPE_CHECKING, Any, Optional, Union
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
|
||||
from twisted.internet.testing import MemoryReactor
|
||||
@@ -48,7 +48,7 @@ thread_local = threading.local()
|
||||
|
||||
|
||||
class LegacyThirdPartyRulesTestModule:
|
||||
def __init__(self, config: Dict, module_api: "ModuleApi") -> None:
|
||||
def __init__(self, config: dict, module_api: "ModuleApi") -> None:
|
||||
# keep a record of the "current" rules module, so that the test can patch
|
||||
# it if desired.
|
||||
thread_local.rules_module = self
|
||||
@@ -65,12 +65,12 @@ class LegacyThirdPartyRulesTestModule:
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def parse_config(config: Dict[str, Any]) -> Dict[str, Any]:
|
||||
def parse_config(config: dict[str, Any]) -> dict[str, Any]:
|
||||
return config
|
||||
|
||||
|
||||
class LegacyDenyNewRooms(LegacyThirdPartyRulesTestModule):
|
||||
def __init__(self, config: Dict, module_api: "ModuleApi") -> None:
|
||||
def __init__(self, config: dict, module_api: "ModuleApi") -> None:
|
||||
super().__init__(config, module_api)
|
||||
|
||||
async def on_create_room(
|
||||
@@ -80,7 +80,7 @@ class LegacyDenyNewRooms(LegacyThirdPartyRulesTestModule):
|
||||
|
||||
|
||||
class LegacyChangeEvents(LegacyThirdPartyRulesTestModule):
|
||||
def __init__(self, config: Dict, module_api: "ModuleApi") -> None:
|
||||
def __init__(self, config: dict, module_api: "ModuleApi") -> None:
|
||||
super().__init__(config, module_api)
|
||||
|
||||
async def check_event_allowed(
|
||||
@@ -150,7 +150,7 @@ class ThirdPartyRulesTestCase(unittest.FederatingHomeserverTestCase):
|
||||
# types
|
||||
async def check(
|
||||
ev: EventBase, state: StateMap[EventBase]
|
||||
) -> Tuple[bool, Optional[JsonDict]]:
|
||||
) -> tuple[bool, Optional[JsonDict]]:
|
||||
return ev.type != "foo.bar.forbidden", None
|
||||
|
||||
callback = Mock(spec=[], side_effect=check)
|
||||
@@ -207,7 +207,7 @@ class ThirdPartyRulesTestCase(unittest.FederatingHomeserverTestCase):
|
||||
# add a callback that will raise our hacky exception
|
||||
async def check(
|
||||
ev: EventBase, state: StateMap[EventBase]
|
||||
) -> Tuple[bool, Optional[JsonDict]]:
|
||||
) -> tuple[bool, Optional[JsonDict]]:
|
||||
raise NastyHackException(429, "message")
|
||||
|
||||
self.hs.get_module_api_callbacks().third_party_event_rules._check_event_allowed_callbacks = [
|
||||
@@ -235,7 +235,7 @@ class ThirdPartyRulesTestCase(unittest.FederatingHomeserverTestCase):
|
||||
# first patch the event checker so that it will try to modify the event
|
||||
async def check(
|
||||
ev: EventBase, state: StateMap[EventBase]
|
||||
) -> Tuple[bool, Optional[JsonDict]]:
|
||||
) -> tuple[bool, Optional[JsonDict]]:
|
||||
ev.content = {"x": "y"}
|
||||
return True, None
|
||||
|
||||
@@ -260,7 +260,7 @@ class ThirdPartyRulesTestCase(unittest.FederatingHomeserverTestCase):
|
||||
# first patch the event checker so that it will modify the event
|
||||
async def check(
|
||||
ev: EventBase, state: StateMap[EventBase]
|
||||
) -> Tuple[bool, Optional[JsonDict]]:
|
||||
) -> tuple[bool, Optional[JsonDict]]:
|
||||
d = ev.get_dict()
|
||||
d["content"] = {"x": "y"}
|
||||
return True, d
|
||||
@@ -295,7 +295,7 @@ class ThirdPartyRulesTestCase(unittest.FederatingHomeserverTestCase):
|
||||
# first patch the event checker so that it will modify the event
|
||||
async def check(
|
||||
ev: EventBase, state: StateMap[EventBase]
|
||||
) -> Tuple[bool, Optional[JsonDict]]:
|
||||
) -> tuple[bool, Optional[JsonDict]]:
|
||||
d = ev.get_dict()
|
||||
d["content"] = {
|
||||
"msgtype": "m.text",
|
||||
@@ -443,7 +443,7 @@ class ThirdPartyRulesTestCase(unittest.FederatingHomeserverTestCase):
|
||||
# Define a callback that sends a custom event on power levels update.
|
||||
async def test_fn(
|
||||
event: EventBase, state_events: StateMap[EventBase]
|
||||
) -> Tuple[bool, Optional[JsonDict]]:
|
||||
) -> tuple[bool, Optional[JsonDict]]:
|
||||
if event.is_state() and event.type == EventTypes.PowerLevels:
|
||||
await api.create_and_send_event_into_room(
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#
|
||||
|
||||
from http import HTTPStatus
|
||||
from typing import Any, Generator, Tuple, cast
|
||||
from typing import Any, Generator, cast
|
||||
from unittest.mock import AsyncMock, Mock, call
|
||||
|
||||
from twisted.internet import defer, reactor as _reactor
|
||||
@@ -92,7 +92,7 @@ class HttpTransactionCacheTestCase(unittest.TestCase):
|
||||
self,
|
||||
) -> Generator["defer.Deferred[Any]", object, None]:
|
||||
@defer.inlineCallbacks
|
||||
def cb() -> Generator["defer.Deferred[object]", object, Tuple[int, JsonDict]]:
|
||||
def cb() -> Generator["defer.Deferred[object]", object, tuple[int, JsonDict]]:
|
||||
# Ignore `multiple-internal-clocks` linter error here since we are creating a `Clock`
|
||||
# for testing purposes.
|
||||
yield defer.ensureDeferred(
|
||||
@@ -124,7 +124,7 @@ class HttpTransactionCacheTestCase(unittest.TestCase):
|
||||
"""
|
||||
called = [False]
|
||||
|
||||
def cb() -> "defer.Deferred[Tuple[int, JsonDict]]":
|
||||
def cb() -> "defer.Deferred[tuple[int, JsonDict]]":
|
||||
if called[0]:
|
||||
# return a valid result the second time
|
||||
return defer.succeed(self.mock_http_response)
|
||||
@@ -156,7 +156,7 @@ class HttpTransactionCacheTestCase(unittest.TestCase):
|
||||
"""
|
||||
called = [False]
|
||||
|
||||
def cb() -> "defer.Deferred[Tuple[int, JsonDict]]":
|
||||
def cb() -> "defer.Deferred[tuple[int, JsonDict]]":
|
||||
if called[0]:
|
||||
# return a valid result the second time
|
||||
return defer.succeed(self.mock_http_response)
|
||||
|
||||
+15
-17
@@ -30,14 +30,12 @@ from typing import (
|
||||
Any,
|
||||
AnyStr,
|
||||
Callable,
|
||||
Dict,
|
||||
Iterable,
|
||||
Literal,
|
||||
Mapping,
|
||||
MutableMapping,
|
||||
Optional,
|
||||
Sequence,
|
||||
Tuple,
|
||||
overload,
|
||||
)
|
||||
from urllib.parse import urlencode
|
||||
@@ -87,8 +85,8 @@ class RestHelper:
|
||||
room_version: Optional[str] = ...,
|
||||
tok: Optional[str] = ...,
|
||||
expect_code: Literal[200] = ...,
|
||||
extra_content: Optional[Dict] = ...,
|
||||
custom_headers: Optional[Iterable[Tuple[AnyStr, AnyStr]]] = ...,
|
||||
extra_content: Optional[dict] = ...,
|
||||
custom_headers: Optional[Iterable[tuple[AnyStr, AnyStr]]] = ...,
|
||||
) -> str: ...
|
||||
|
||||
@overload
|
||||
@@ -99,8 +97,8 @@ class RestHelper:
|
||||
room_version: Optional[str] = ...,
|
||||
tok: Optional[str] = ...,
|
||||
expect_code: int = ...,
|
||||
extra_content: Optional[Dict] = ...,
|
||||
custom_headers: Optional[Iterable[Tuple[AnyStr, AnyStr]]] = ...,
|
||||
extra_content: Optional[dict] = ...,
|
||||
custom_headers: Optional[Iterable[tuple[AnyStr, AnyStr]]] = ...,
|
||||
) -> Optional[str]: ...
|
||||
|
||||
def create_room_as(
|
||||
@@ -110,8 +108,8 @@ class RestHelper:
|
||||
room_version: Optional[str] = None,
|
||||
tok: Optional[str] = None,
|
||||
expect_code: int = HTTPStatus.OK,
|
||||
extra_content: Optional[Dict] = None,
|
||||
custom_headers: Optional[Iterable[Tuple[AnyStr, AnyStr]]] = None,
|
||||
extra_content: Optional[dict] = None,
|
||||
custom_headers: Optional[Iterable[tuple[AnyStr, AnyStr]]] = None,
|
||||
) -> Optional[str]:
|
||||
"""
|
||||
Create a room.
|
||||
@@ -310,7 +308,7 @@ class RestHelper:
|
||||
self.auth_user_id = src
|
||||
|
||||
path = f"/_matrix/client/r0/rooms/{room}/state/m.room.member/{targ}"
|
||||
url_params: Dict[str, str] = {}
|
||||
url_params: dict[str, str] = {}
|
||||
|
||||
if tok:
|
||||
url_params["access_token"] = tok
|
||||
@@ -378,7 +376,7 @@ class RestHelper:
|
||||
txn_id: Optional[str] = None,
|
||||
tok: Optional[str] = None,
|
||||
expect_code: int = HTTPStatus.OK,
|
||||
custom_headers: Optional[Iterable[Tuple[AnyStr, AnyStr]]] = None,
|
||||
custom_headers: Optional[Iterable[tuple[AnyStr, AnyStr]]] = None,
|
||||
type: str = "m.room.message",
|
||||
) -> JsonDict:
|
||||
if body is None:
|
||||
@@ -430,7 +428,7 @@ class RestHelper:
|
||||
txn_id: Optional[str] = None,
|
||||
tok: Optional[str] = None,
|
||||
expect_code: int = HTTPStatus.OK,
|
||||
custom_headers: Optional[Iterable[Tuple[AnyStr, AnyStr]]] = None,
|
||||
custom_headers: Optional[Iterable[tuple[AnyStr, AnyStr]]] = None,
|
||||
) -> JsonDict:
|
||||
if txn_id is None:
|
||||
txn_id = "m%s" % (str(time.time()))
|
||||
@@ -497,7 +495,7 @@ class RestHelper:
|
||||
self,
|
||||
room_id: str,
|
||||
event_type: str,
|
||||
body: Optional[Dict[str, Any]],
|
||||
body: Optional[dict[str, Any]],
|
||||
tok: Optional[str],
|
||||
expect_code: int = HTTPStatus.OK,
|
||||
state_key: str = "",
|
||||
@@ -575,7 +573,7 @@ class RestHelper:
|
||||
self,
|
||||
room_id: str,
|
||||
event_type: str,
|
||||
body: Dict[str, Any],
|
||||
body: dict[str, Any],
|
||||
tok: Optional[str] = None,
|
||||
expect_code: int = HTTPStatus.OK,
|
||||
state_key: str = "",
|
||||
@@ -684,7 +682,7 @@ class RestHelper:
|
||||
with_sid: bool = False,
|
||||
idp_id: Optional[str] = None,
|
||||
expected_status: int = 200,
|
||||
) -> Tuple[JsonDict, FakeAuthorizationGrant]:
|
||||
) -> tuple[JsonDict, FakeAuthorizationGrant]:
|
||||
"""Log in (as a new user) via OIDC
|
||||
|
||||
Returns the result of the final token login and the fake authorization grant.
|
||||
@@ -757,7 +755,7 @@ class RestHelper:
|
||||
ui_auth_session_id: Optional[str] = None,
|
||||
with_sid: bool = False,
|
||||
idp_id: Optional[str] = None,
|
||||
) -> Tuple[FakeChannel, FakeAuthorizationGrant]:
|
||||
) -> tuple[FakeChannel, FakeAuthorizationGrant]:
|
||||
"""Perform an OIDC authentication flow via a mock OIDC provider.
|
||||
|
||||
This can be used for either login or user-interactive auth.
|
||||
@@ -790,7 +788,7 @@ class RestHelper:
|
||||
went.
|
||||
"""
|
||||
|
||||
cookies: Dict[str, str] = {}
|
||||
cookies: dict[str, str] = {}
|
||||
|
||||
with fake_server.patch_homeserver(hs=self.hs):
|
||||
# if we're doing a ui auth, hit the ui auth redirect endpoint
|
||||
@@ -824,7 +822,7 @@ class RestHelper:
|
||||
cookies: Mapping[str, str],
|
||||
user_info_dict: JsonDict,
|
||||
with_sid: bool = False,
|
||||
) -> Tuple[FakeChannel, FakeAuthorizationGrant]:
|
||||
) -> tuple[FakeChannel, FakeAuthorizationGrant]:
|
||||
"""Mock out an OIDC authentication flow
|
||||
|
||||
Assumes that an OIDC auth has been initiated by one of initiate_sso_login or
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#
|
||||
#
|
||||
from io import BytesIO, StringIO
|
||||
from typing import Any, Dict, Optional, Union
|
||||
from typing import Any, Optional, Union
|
||||
from unittest.mock import Mock
|
||||
|
||||
import signedjson.key
|
||||
@@ -156,7 +156,7 @@ class EndToEndPerspectivesTests(BaseRemoteKeyResourceTestCase):
|
||||
endpoint, to check that the two implementations are compatible.
|
||||
"""
|
||||
|
||||
def default_config(self) -> Dict[str, Any]:
|
||||
def default_config(self) -> dict[str, Any]:
|
||||
config = super().default_config()
|
||||
|
||||
# replace the signing key with our own
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
# [This file includes modifications made by New Vector Limited]
|
||||
#
|
||||
#
|
||||
from typing import Dict
|
||||
|
||||
from twisted.internet.testing import MemoryReactor
|
||||
from twisted.web.resource import Resource
|
||||
@@ -65,7 +64,7 @@ class MediaDomainBlockingTests(unittest.HomeserverTestCase):
|
||||
)
|
||||
)
|
||||
|
||||
def create_resource_dict(self) -> Dict[str, Resource]:
|
||||
def create_resource_dict(self) -> dict[str, Resource]:
|
||||
# We need to manually set the resource tree to include media, the
|
||||
# default only does `/_matrix/client` APIs.
|
||||
return {"/_matrix/media": self.hs.get_media_repository_resource()}
|
||||
|
||||
@@ -22,7 +22,7 @@ import base64
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from typing import Any, Dict, Optional, Sequence, Tuple, Type
|
||||
from typing import Any, Optional, Sequence
|
||||
from urllib.parse import quote, urlencode
|
||||
|
||||
from twisted.internet._resolver import HostResolution
|
||||
@@ -127,7 +127,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||
assert self.media_repo.url_previewer is not None
|
||||
self.url_previewer = self.media_repo.url_previewer
|
||||
|
||||
self.lookups: Dict[str, Any] = {}
|
||||
self.lookups: dict[str, Any] = {}
|
||||
|
||||
class Resolver:
|
||||
def resolveHostName(
|
||||
@@ -135,7 +135,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||
resolutionReceiver: IResolutionReceiver,
|
||||
hostName: str,
|
||||
portNumber: int = 0,
|
||||
addressTypes: Optional[Sequence[Type[IAddress]]] = None,
|
||||
addressTypes: Optional[Sequence[type[IAddress]]] = None,
|
||||
transportSemantics: str = "TCP",
|
||||
) -> IResolutionReceiver:
|
||||
resolution = HostResolution(hostName)
|
||||
@@ -150,7 +150,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||
|
||||
self.reactor.nameResolver = Resolver() # type: ignore[assignment]
|
||||
|
||||
def create_resource_dict(self) -> Dict[str, Resource]:
|
||||
def create_resource_dict(self) -> dict[str, Resource]:
|
||||
"""Create a resource tree for the test server
|
||||
|
||||
A resource tree is a mapping from path to twisted.web.resource.
|
||||
@@ -1227,7 +1227,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||
self.assertEqual(body["og:title"], "Test")
|
||||
self.assertNotIn("og:image", body)
|
||||
|
||||
def _download_image(self) -> Tuple[str, str]:
|
||||
def _download_image(self) -> tuple[str, str]:
|
||||
"""Downloads an image into the URL cache.
|
||||
Returns:
|
||||
A (host, media_id) tuple representing the MXC URI of the image.
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
# See the GNU Affero General Public License for more details:
|
||||
# <https://www.gnu.org/licenses/agpl-3.0.html>.
|
||||
|
||||
from typing import Dict
|
||||
|
||||
from twisted.web.resource import Resource
|
||||
|
||||
@@ -28,7 +27,7 @@ class FederationWhitelistTests(unittest.HomeserverTestCase):
|
||||
login.register_servlets,
|
||||
]
|
||||
|
||||
def create_resource_dict(self) -> Dict[str, Resource]:
|
||||
def create_resource_dict(self) -> dict[str, Resource]:
|
||||
base = super().create_resource_dict()
|
||||
base.update(build_synapse_client_resource_tree(self.hs))
|
||||
return base
|
||||
|
||||
Reference in New Issue
Block a user