1
0

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

View File

@@ -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

View File

@@ -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)

View File

@@ -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:

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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")

View File

@@ -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.

View File

@@ -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

View File

@@ -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: