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

@@ -21,7 +21,7 @@ import email.message
import importlib.resources as importlib_resources
import os
from http import HTTPStatus
from typing import Any, Dict, List, Sequence, Tuple
from typing import Any, Sequence
import attr
from parameterized import parameterized
@@ -83,8 +83,8 @@ class EmailPusherTests(HomeserverTestCase):
hs = self.setup_test_homeserver(config=config)
# List[Tuple[Deferred, args, kwargs]]
self.email_attempts: List[Tuple[Deferred, Sequence, Dict]] = []
# list[tuple[Deferred, args, kwargs]]
self.email_attempts: list[tuple[Deferred, Sequence, dict]] = []
def sendmail(*args: Any, **kwargs: Any) -> Deferred:
# This mocks out synapse.reactor.send_email._sendmail.
@@ -510,7 +510,7 @@ class EmailPusherTests(HomeserverTestCase):
)
self.assertEqual(len(pushers), 0)
def _check_for_mail(self) -> Tuple[Sequence, Dict]:
def _check_for_mail(self) -> tuple[Sequence, dict]:
"""
Assert that synapse sent off exactly one email notification.

View File

@@ -17,7 +17,7 @@
# [This file includes modifications made by New Vector Limited]
#
#
from typing import Any, Dict, List, Tuple
from typing import Any
from unittest.mock import Mock
from parameterized import parameterized
@@ -51,7 +51,7 @@ class HTTPPusherTests(HomeserverTestCase):
hijack_auth = False
def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
self.push_attempts: List[Tuple[Deferred, str, dict]] = []
self.push_attempts: list[tuple[Deferred, str, dict]] = []
m = Mock()
@@ -747,7 +747,7 @@ class HTTPPusherTests(HomeserverTestCase):
def _make_user_with_pusher(
self, username: str, enabled: bool = True
) -> Tuple[str, str]:
) -> tuple[str, str]:
"""Registers a user and creates a pusher for them.
Args:
@@ -925,7 +925,7 @@ class HTTPPusherTests(HomeserverTestCase):
ret = self.get_success(
self.hs.get_datastores().main.get_pushers_by({"user_name": user_id})
)
pushers: List[PusherConfig] = list(ret)
pushers: list[PusherConfig] = list(ret)
# Check that we still have one pusher, and that the device ID associated with
# it didn't change.
@@ -1118,7 +1118,7 @@ class HTTPPusherTests(HomeserverTestCase):
device_id = user_tuple.device_id
# Set the push data dict based on test input parameters
push_data: Dict[str, Any] = {
push_data: dict[str, Any] = {
"url": "http://example.com/_matrix/push/v1/notify",
}
if disable_badge_count:

View File

@@ -19,7 +19,7 @@
#
#
from typing import Iterable, List, Optional, Tuple, cast
from typing import Iterable, Optional, cast
from synapse.api.constants import EventTypes, Membership
from synapse.api.room_versions import RoomVersions
@@ -36,7 +36,7 @@ class MockDataStore:
(I.e. the state key is used as the event ID.)
"""
def __init__(self, events: Iterable[Tuple[StateKey, dict]]):
def __init__(self, events: Iterable[tuple[StateKey, dict]]):
"""
Args:
events: A state map to event contents.
@@ -63,7 +63,7 @@ class MockDataStore:
assert allow_none, "Mock not configured for allow_none = False"
# Decode the state key from the event ID.
state_key = cast(Tuple[str, str], tuple(event_id.split("|", 1)))
state_key = cast(tuple[str, str], tuple(event_id.split("|", 1)))
return self._events.get(state_key)
async def get_events(self, event_ids: Iterable[StateKey]) -> StateMap[EventBase]:
@@ -77,7 +77,7 @@ class PresentableNamesTestCase(unittest.HomeserverTestCase):
def _calculate_room_name(
self,
events: Iterable[Tuple[Tuple[str, str], dict]],
events: Iterable[tuple[tuple[str, str], dict]],
user_id: str = "",
fallback_to_members: bool = True,
fallback_to_single_member: bool = True,
@@ -97,7 +97,7 @@ class PresentableNamesTestCase(unittest.HomeserverTestCase):
def test_name(self) -> None:
"""A room name event should be used."""
events: List[Tuple[Tuple[str, str], dict]] = [
events: list[tuple[tuple[str, str], dict]] = [
((EventTypes.Name, ""), {"name": "test-name"}),
]
self.assertEqual("test-name", self._calculate_room_name(events))
@@ -111,7 +111,7 @@ class PresentableNamesTestCase(unittest.HomeserverTestCase):
def test_canonical_alias(self) -> None:
"""An canonical alias should be used."""
events: List[Tuple[Tuple[str, str], dict]] = [
events: list[tuple[tuple[str, str], dict]] = [
((EventTypes.CanonicalAlias, ""), {"alias": "#test-name:test"}),
]
self.assertEqual("#test-name:test", self._calculate_room_name(events))
@@ -125,7 +125,7 @@ class PresentableNamesTestCase(unittest.HomeserverTestCase):
def test_invite(self) -> None:
"""An invite has special behaviour."""
events: List[Tuple[Tuple[str, str], dict]] = [
events: list[tuple[tuple[str, str], dict]] = [
((EventTypes.Member, self.USER_ID), {"membership": Membership.INVITE}),
((EventTypes.Member, self.OTHER_USER_ID), {"displayname": "Other User"}),
]
@@ -151,7 +151,7 @@ class PresentableNamesTestCase(unittest.HomeserverTestCase):
def test_no_members(self) -> None:
"""Behaviour of an empty room."""
events: List[Tuple[Tuple[str, str], dict]] = []
events: list[tuple[tuple[str, str], dict]] = []
self.assertEqual("Empty Room", self._calculate_room_name(events))
# Note that events with invalid (or missing) membership are ignored.

View File

@@ -19,7 +19,7 @@
#
#
from typing import Any, Dict, List, Optional, Union, cast
from typing import Any, Optional, Union, cast
from twisted.internet.testing import MemoryReactor
@@ -60,7 +60,7 @@ class FlattenDictTestCase(unittest.TestCase):
def test_non_string(self) -> None:
"""String, booleans, ints, nulls and list of those should be kept while other items are dropped."""
input: Dict[str, Any] = {
input: dict[str, Any] = {
"woo": "woo",
"foo": True,
"bar": 1,
@@ -165,13 +165,13 @@ class PushRuleEvaluatorTestCase(unittest.TestCase):
)
room_member_count = 0
sender_power_level = 0
power_levels: Dict[str, Union[int, Dict[str, int]]] = {}
power_levels: dict[str, Union[int, dict[str, int]]] = {}
return PushRuleEvaluator(
_flatten_dict(event),
False,
room_member_count,
sender_power_level,
cast(Dict[str, int], power_levels.get("notifications", {})),
cast(dict[str, int], power_levels.get("notifications", {})),
{} if related_events is None else related_events,
related_event_match_enabled=True,
room_version_feature_flags=event.room_version.msc3931_push_features,
@@ -588,7 +588,7 @@ class PushRuleEvaluatorTestCase(unittest.TestCase):
This tests the behaviour of tweaks_for_actions.
"""
actions: List[Union[Dict[str, str], str]] = [
actions: list[Union[dict[str, str], str]] = [
{"set_tweak": "sound", "value": "default"},
{"set_tweak": "highlight"},
"notify",