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

@@ -19,7 +19,7 @@
#
import logging
from collections import defaultdict
from typing import Any, Dict, List, Optional, Set, Tuple
from typing import Any, Optional
from twisted.internet.address import IPv4Address
from twisted.internet.protocol import Protocol, connectionDone
@@ -108,7 +108,7 @@ class BaseStreamTestCase(unittest.HomeserverTestCase):
self._client_transport: Optional[FakeTransport] = None
self._server_transport: Optional[FakeTransport] = None
def create_resource_dict(self) -> Dict[str, Resource]:
def create_resource_dict(self) -> dict[str, Resource]:
d = super().create_resource_dict()
d["/_synapse/replication"] = ReplicationRestResource(self.hs)
return d
@@ -183,7 +183,7 @@ class BaseStreamTestCase(unittest.HomeserverTestCase):
# hook into the channel's request factory so that we can keep a record
# of the requests
requests: List[SynapseRequest] = []
requests: list[SynapseRequest] = []
real_request_factory = channel.requestFactory
def request_factory(*args: Any, **kwargs: Any) -> SynapseRequest:
@@ -256,7 +256,7 @@ class BaseMultiWorkerStreamTestCase(unittest.HomeserverTestCase):
# Redis replication only takes place on Postgres
skip = "Requires Postgres"
def default_config(self) -> Dict[str, Any]:
def default_config(self) -> dict[str, Any]:
"""
Overrides the default config to enable Redis.
Even if the test only uses make_worker_hs, the main process needs Redis
@@ -491,7 +491,7 @@ class TestReplicationDataHandler(ReplicationDataHandler):
super().__init__(hs)
# list of received (stream_name, token, row) tuples
self.received_rdata_rows: List[Tuple[str, int, Any]] = []
self.received_rdata_rows: list[tuple[str, int, Any]] = []
async def on_rdata(
self, stream_name: str, instance_name: str, token: int, rows: list
@@ -505,7 +505,7 @@ class FakeRedisPubSubServer:
"""A fake Redis server for pub/sub."""
def __init__(self) -> None:
self._subscribers_by_channel: Dict[bytes, Set["FakeRedisPubSubProtocol"]] = (
self._subscribers_by_channel: dict[bytes, set["FakeRedisPubSubProtocol"]] = (
defaultdict(set)
)

View File

@@ -20,7 +20,6 @@
#
from http import HTTPStatus
from typing import Tuple
from twisted.web.server import Request
@@ -52,7 +51,7 @@ class CancellableReplicationEndpoint(ReplicationEndpoint):
@cancellable
async def _handle_request( # type: ignore[override]
self, request: Request, content: JsonDict
) -> Tuple[int, JsonDict]:
) -> tuple[int, JsonDict]:
await self.clock.sleep(1.0)
return HTTPStatus.OK, {"result": True}
@@ -73,7 +72,7 @@ class UncancellableReplicationEndpoint(ReplicationEndpoint):
async def _handle_request( # type: ignore[override]
self, request: Request, content: JsonDict
) -> Tuple[int, JsonDict]:
) -> tuple[int, JsonDict]:
await self.clock.sleep(1.0)
return HTTPStatus.OK, {"result": True}

View File

@@ -19,7 +19,7 @@
#
#
import logging
from typing import Any, Iterable, List, Optional, Tuple
from typing import Any, Iterable, Optional
from canonicaljson import encode_canonical_json
from parameterized import parameterized
@@ -244,13 +244,13 @@ class EventsWorkerStoreTestCase(BaseWorkerStoreTestCase):
key: Optional[str] = None,
internal: Optional[dict] = None,
depth: Optional[int] = None,
prev_events: Optional[List[Tuple[str, dict]]] = None,
auth_events: Optional[List[str]] = None,
prev_state: Optional[List[str]] = None,
prev_events: Optional[list[tuple[str, dict]]] = None,
auth_events: Optional[list[str]] = None,
prev_state: Optional[list[str]] = None,
redacts: Optional[str] = None,
push_actions: Iterable = frozenset(),
**content: object,
) -> Tuple[EventBase, EventContext]:
) -> tuple[EventBase, EventContext]:
prev_events = prev_events or []
auth_events = auth_events or []
prev_state = prev_state or []

View File

@@ -18,7 +18,7 @@
#
#
from typing import Any, List, Optional
from typing import Any, Optional
from parameterized import parameterized
@@ -299,7 +299,7 @@ class EventsStreamTestCase(BaseStreamTestCase):
self.assertEqual(row.data.event_id, pl_event.event_id)
# the state rows are unsorted
state_rows: List[EventsStreamCurrentStateRow] = []
state_rows: list[EventsStreamCurrentStateRow] = []
for stream_name, _, row in received_event_rows:
self.assertEqual("events", stream_name)
self.assertIsInstance(row, EventsStreamRow)
@@ -355,7 +355,7 @@ class EventsStreamTestCase(BaseStreamTestCase):
self.hs.get_datastores().main.get_latest_event_ids_in_room(self.room_id)
)
events: List[EventBase] = []
events: list[EventBase] = []
for user in user_ids:
events.extend(
self._inject_state_event(sender=user) for _ in range(STATES_PER_USER)
@@ -426,7 +426,7 @@ class EventsStreamTestCase(BaseStreamTestCase):
self.assertEqual(row.data.event_id, pl_events[i].event_id)
# the state rows are unsorted
state_rows: List[EventsStreamCurrentStateRow] = []
state_rows: list[EventsStreamCurrentStateRow] = []
for _ in range(STATES_PER_USER + 1):
stream_name, token, row = received_event_rows.pop(0)
self.assertEqual("events", stream_name)

View File

@@ -20,7 +20,7 @@
#
import logging
import os
from typing import Any, Optional, Tuple
from typing import Any, Optional
from twisted.internet.protocol import Factory
from twisted.internet.testing import MemoryReactor
@@ -78,7 +78,7 @@ class MediaRepoShardTestCase(BaseMultiWorkerStreamTestCase):
def _get_media_req(
self, hs: HomeServer, target: str, media_id: str
) -> Tuple[FakeChannel, Request]:
) -> tuple[FakeChannel, Request]:
"""Request some remote media from the given HS by calling the download
API.
@@ -293,7 +293,7 @@ class AuthenticatedMediaRepoShardTestCase(BaseMultiWorkerStreamTestCase):
def _get_media_req(
self, hs: HomeServer, target: str, media_id: str
) -> Tuple[FakeChannel, Request]:
) -> tuple[FakeChannel, Request]:
"""Request some remote media from the given HS by calling the download
API.