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
+6 -6
View File
@@ -1,4 +1,4 @@
from typing import Callable, Collection, List, Optional, Tuple
from typing import Callable, Collection, Optional
from unittest import mock
from unittest.mock import AsyncMock, Mock
@@ -55,8 +55,8 @@ class FederationCatchUpTestCases(FederatingHomeserverTestCase):
)
# whenever send_transaction is called, record the pdu data
self.pdus: List[JsonDict] = []
self.failed_pdus: List[JsonDict] = []
self.pdus: list[JsonDict] = []
self.failed_pdus: list[JsonDict] = []
self.is_online = True
self.federation_transport_client.send_transaction.side_effect = (
self.record_transaction
@@ -269,7 +269,7 @@ class FederationCatchUpTestCases(FederatingHomeserverTestCase):
def make_fake_destination_queue(
self, destination: str = "host2"
) -> Tuple[PerDestinationQueue, List[EventBase]]:
) -> tuple[PerDestinationQueue, list[EventBase]]:
"""
Makes a fake per-destination queue.
"""
@@ -279,8 +279,8 @@ class FederationCatchUpTestCases(FederatingHomeserverTestCase):
async def fake_send(
destination_tm: str,
pending_pdus: List[EventBase],
_pending_edus: List[Edu],
pending_pdus: list[EventBase],
_pending_edus: list[Edu],
) -> None:
assert destination == destination_tm
results_list.extend(pending_pdus)
@@ -23,7 +23,7 @@ import logging
import time
import urllib.parse
from http import HTTPStatus
from typing import Any, Callable, Optional, Set, Tuple, TypeVar, Union
from typing import Any, Callable, Optional, TypeVar, Union
from unittest.mock import Mock
import attr
@@ -147,7 +147,7 @@ class OutOfBandMembershipTests(unittest.FederatingHomeserverTestCase):
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.
@@ -350,7 +350,7 @@ class OutOfBandMembershipTests(unittest.FederatingHomeserverTestCase):
self.federation_http_client.get_json.side_effect = get_json
# PDU's that hs1 sent to hs2
collected_pdus_from_hs1_federation_send: Set[str] = set()
collected_pdus_from_hs1_federation_send: set[str] = set()
async def put_json(
destination: str,
@@ -503,7 +503,7 @@ class OutOfBandMembershipTests(unittest.FederatingHomeserverTestCase):
T = TypeVar("T")
# PDU's that hs1 sent to hs2
collected_pdus_from_hs1_federation_send: Set[str] = set()
collected_pdus_from_hs1_federation_send: set[str] = set()
async def put_json(
destination: str,
+5 -5
View File
@@ -17,7 +17,7 @@
# [This file includes modifications made by New Vector Limited]
#
#
from typing import Callable, FrozenSet, List, Optional, Set
from typing import Callable, Optional
from unittest.mock import AsyncMock, Mock
from signedjson import key, sign
@@ -435,7 +435,7 @@ class FederationSenderPresenceTestCases(HomeserverTestCase):
# A set of all user presence we see, this should end up matching the
# number we sent out above.
seen_users: Set[str] = set()
seen_users: set[str] = set()
for edu in presence_edus:
presence_states = edu["content"]["push"]
@@ -483,12 +483,12 @@ class FederationSenderDevicesTestCases(HomeserverTestCase):
# stub out `get_rooms_for_user` and `get_current_hosts_in_room` so that the
# server thinks the user shares a room with `@user2:host2`
def get_rooms_for_user(user_id: str) -> "defer.Deferred[FrozenSet[str]]":
def get_rooms_for_user(user_id: str) -> "defer.Deferred[frozenset[str]]":
return defer.succeed(frozenset({test_room_id}))
hs.get_datastores().main.get_rooms_for_user = get_rooms_for_user # type: ignore[assignment]
async def get_current_hosts_in_room(room_id: str) -> Set[str]:
async def get_current_hosts_in_room(room_id: str) -> set[str]:
if room_id == test_room_id:
return {"host2"}
else:
@@ -504,7 +504,7 @@ class FederationSenderDevicesTestCases(HomeserverTestCase):
self.device_handler = device_handler
# whenever send_transaction is called, record the edu data
self.edus: List[JsonDict] = []
self.edus: list[JsonDict] = []
self.federation_transport_client.send_transaction.side_effect = (
self.record_transaction
)
@@ -20,7 +20,6 @@
#
from http import HTTPStatus
from typing import Dict, List, Tuple
from twisted.web.resource import Resource
@@ -52,14 +51,14 @@ class CancellableFederationServlet(BaseFederationServlet):
@cancellable
async def on_GET(
self, origin: str, content: None, query: Dict[bytes, List[bytes]]
) -> Tuple[int, JsonDict]:
self, origin: str, content: None, query: dict[bytes, list[bytes]]
) -> tuple[int, JsonDict]:
await self.clock.sleep(1.0)
return HTTPStatus.OK, {"result": True}
async def on_POST(
self, origin: str, content: JsonDict, query: Dict[bytes, List[bytes]]
) -> Tuple[int, JsonDict]:
self, origin: str, content: JsonDict, query: dict[bytes, list[bytes]]
) -> tuple[int, JsonDict]:
await self.clock.sleep(1.0)
return HTTPStatus.OK, {"result": True}
+2 -2
View File
@@ -20,7 +20,7 @@
#
import json
from typing import List, Optional
from typing import Optional
from unittest.mock import Mock
import ijson.common
@@ -98,7 +98,7 @@ class SendJoinParserTestCase(TestCase):
def test_servers_in_room(self) -> None:
"""Check that the servers_in_room field is correctly parsed"""
def parse(response: JsonDict) -> Optional[List[str]]:
def parse(response: JsonDict) -> Optional[list[str]]:
parser = SendJoinParser(RoomVersions.V1, False)
serialised_response = json.dumps(response).encode()
+3 -3
View File
@@ -19,7 +19,7 @@
#
#
from collections import OrderedDict
from typing import Any, Dict, List, Optional
from typing import Any, Optional
from twisted.internet.testing import MemoryReactor
@@ -161,8 +161,8 @@ class KnockingStrippedStateEventHelperMixin(HomeserverTestCase):
def check_knock_room_state_against_room_state(
self,
knock_room_state: List[Dict],
expected_room_state: Dict,
knock_room_state: list[dict],
expected_room_state: dict,
) -> None:
"""Test a list of stripped room state events received over federation against a
dict of expected state events.