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:
committed by
GitHub
parent
cba3a814c6
commit
fc244bb592
@@ -33,16 +33,12 @@ from typing import (
|
||||
Awaitable,
|
||||
Callable,
|
||||
ClassVar,
|
||||
Dict,
|
||||
Generic,
|
||||
Iterable,
|
||||
List,
|
||||
Mapping,
|
||||
NoReturn,
|
||||
Optional,
|
||||
Protocol,
|
||||
Tuple,
|
||||
Type,
|
||||
TypeVar,
|
||||
Union,
|
||||
)
|
||||
@@ -169,7 +165,7 @@ def _parse_config_dict(config: str) -> HomeServerConfig:
|
||||
return config_obj
|
||||
|
||||
|
||||
def make_homeserver_config_obj(config: Dict[str, Any]) -> HomeServerConfig:
|
||||
def make_homeserver_config_obj(config: dict[str, Any]) -> HomeServerConfig:
|
||||
"""Creates a :class:`HomeServerConfig` instance with the given configuration dict.
|
||||
|
||||
This is equivalent to::
|
||||
@@ -250,7 +246,7 @@ class TestCase(unittest.TestCase):
|
||||
|
||||
return ret
|
||||
|
||||
def assertObjectHasAttributes(self, attrs: Dict[str, object], obj: object) -> None:
|
||||
def assertObjectHasAttributes(self, attrs: dict[str, object], obj: object) -> None:
|
||||
"""Asserts that the given object has each of the attributes given, and
|
||||
that the value of each matches according to assertEqual."""
|
||||
for key in attrs.keys():
|
||||
@@ -299,14 +295,14 @@ class TestCase(unittest.TestCase):
|
||||
elif not exact and 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(
|
||||
@@ -379,7 +375,7 @@ class HomeserverTestCase(TestCase):
|
||||
|
||||
hijack_auth: ClassVar[bool] = True
|
||||
needs_threadpool: ClassVar[bool] = False
|
||||
servlets: ClassVar[List[RegisterServletsFunc]] = []
|
||||
servlets: ClassVar[list[RegisterServletsFunc]] = []
|
||||
|
||||
def __init__(self, methodName: str):
|
||||
super().__init__(methodName)
|
||||
@@ -527,7 +523,7 @@ class HomeserverTestCase(TestCase):
|
||||
create_resource_tree(self.create_resource_dict(), root_resource)
|
||||
return root_resource
|
||||
|
||||
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.
|
||||
@@ -578,7 +574,7 @@ class HomeserverTestCase(TestCase):
|
||||
path: Union[bytes, str],
|
||||
content: Union[bytes, str, JsonDict] = b"",
|
||||
access_token: Optional[str] = None,
|
||||
request: Type[Request] = SynapseRequest,
|
||||
request: type[Request] = SynapseRequest,
|
||||
shorthand: bool = True,
|
||||
federation_auth_origin: Optional[bytes] = None,
|
||||
content_type: Optional[bytes] = None,
|
||||
@@ -709,7 +705,7 @@ class HomeserverTestCase(TestCase):
|
||||
return self.successResultOf(deferred)
|
||||
|
||||
def get_failure(
|
||||
self, d: Awaitable[Any], exc: Type[_ExcType], by: float = 0.0
|
||||
self, d: Awaitable[Any], exc: type[_ExcType], by: float = 0.0
|
||||
) -> _TypedFailure[_ExcType]:
|
||||
"""
|
||||
Run a Deferred and get a Failure from it. The failure must be of the type `exc`.
|
||||
@@ -799,7 +795,7 @@ class HomeserverTestCase(TestCase):
|
||||
username: str,
|
||||
appservice_token: str,
|
||||
inhibit_login: bool = False,
|
||||
) -> Tuple[str, Optional[str]]:
|
||||
) -> tuple[str, Optional[str]]:
|
||||
"""Register an appservice user as an application service.
|
||||
Requires the client-facing registration API be registered.
|
||||
|
||||
@@ -831,7 +827,7 @@ class HomeserverTestCase(TestCase):
|
||||
username: str,
|
||||
password: str,
|
||||
device_id: Optional[str] = None,
|
||||
additional_request_fields: Optional[Dict[str, str]] = None,
|
||||
additional_request_fields: Optional[dict[str, str]] = None,
|
||||
custom_headers: Optional[Iterable[CustomHeaderType]] = None,
|
||||
) -> str:
|
||||
"""
|
||||
@@ -871,7 +867,7 @@ class HomeserverTestCase(TestCase):
|
||||
room_id: str,
|
||||
user: UserID,
|
||||
soft_failed: bool = False,
|
||||
prev_event_ids: Optional[List[str]] = None,
|
||||
prev_event_ids: Optional[list[str]] = None,
|
||||
) -> str:
|
||||
"""
|
||||
Create and send an event.
|
||||
@@ -963,7 +959,7 @@ class FederatingHomeserverTestCase(HomeserverTestCase):
|
||||
)
|
||||
)
|
||||
|
||||
def create_resource_dict(self) -> Dict[str, Resource]:
|
||||
def create_resource_dict(self) -> dict[str, Resource]:
|
||||
d = super().create_resource_dict()
|
||||
d["/_matrix/federation"] = TransportLayerServer(self.hs)
|
||||
return d
|
||||
|
||||
Reference in New Issue
Block a user