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

@@ -28,7 +28,7 @@ import json
import sys
import warnings
from binascii import unhexlify
from typing import TYPE_CHECKING, Awaitable, Callable, Tuple, TypeVar
from typing import TYPE_CHECKING, Awaitable, Callable, TypeVar
import attr
import zope.interface
@@ -102,7 +102,7 @@ class FakeResponse: # type: ignore[misc]
attribute, and didn't support deliverBody until recently.
"""
version: Tuple[bytes, int, int] = (b"HTTP", 1, 1)
version: tuple[bytes, int, int] = (b"HTTP", 1, 1)
# HTTP response code
code: int = 200

View File

@@ -18,7 +18,7 @@
# [This file includes modifications made by New Vector Limited]
#
#
from typing import Any, List, Optional, Tuple
from typing import Any, Optional
import synapse.server
from synapse.api.constants import EventTypes
@@ -62,7 +62,7 @@ async def inject_member_event(
async def inject_event(
hs: synapse.server.HomeServer,
room_version: Optional[str] = None,
prev_event_ids: Optional[List[str]] = None,
prev_event_ids: Optional[list[str]] = None,
**kwargs: Any,
) -> EventBase:
"""Inject a generic event into a room
@@ -87,9 +87,9 @@ async def inject_event(
async def create_event(
hs: synapse.server.HomeServer,
room_version: Optional[str] = None,
prev_event_ids: Optional[List[str]] = None,
prev_event_ids: Optional[list[str]] = None,
**kwargs: Any,
) -> Tuple[EventBase, EventContext]:
) -> tuple[EventBase, EventContext]:
if room_version is None:
room_version = await hs.get_datastores().main.get_room_version_id(
kwargs["room_id"]

View File

@@ -20,7 +20,7 @@
#
from html.parser import HTMLParser
from typing import Dict, Iterable, List, NoReturn, Optional, Tuple
from typing import Iterable, NoReturn, Optional
class TestHtmlParser(HTMLParser):
@@ -30,16 +30,16 @@ class TestHtmlParser(HTMLParser):
super().__init__()
# a list of links found in the doc
self.links: List[str] = []
self.links: list[str] = []
# the values of any hidden <input>s: map from name to value
self.hiddens: Dict[str, Optional[str]] = {}
self.hiddens: dict[str, Optional[str]] = {}
# the values of any radio buttons: map from name to list of values
self.radios: Dict[str, List[Optional[str]]] = {}
self.radios: dict[str, list[Optional[str]]] = {}
def handle_starttag(
self, tag: str, attrs: Iterable[Tuple[str, Optional[str]]]
self, tag: str, attrs: Iterable[tuple[str, Optional[str]]]
) -> None:
attr_dict = dict(attrs)
if tag == "a":

View File

@@ -23,7 +23,7 @@
import base64
import json
from hashlib import sha256
from typing import Any, ContextManager, Dict, List, Optional, Tuple
from typing import Any, ContextManager, Optional
from unittest.mock import Mock, patch
from urllib.parse import parse_qs
@@ -75,16 +75,16 @@ class FakeOidcServer:
self.post_token_handler = Mock(side_effect=self._post_token_handler)
# A code -> grant mapping
self._authorization_grants: Dict[str, FakeAuthorizationGrant] = {}
self._authorization_grants: dict[str, FakeAuthorizationGrant] = {}
# An access token -> grant mapping
self._sessions: Dict[str, FakeAuthorizationGrant] = {}
self._sessions: dict[str, FakeAuthorizationGrant] = {}
# We generate here an ECDSA key with the P-256 curve (ES256 algorithm) used for
# signing JWTs. ECDSA keys are really quick to generate compared to RSA.
self._key = ECKey.generate_key(crv="P-256", is_private=True)
self._jwks = KeySet([ECKey.import_key(self._key.as_pem(is_private=False))])
self._id_token_overrides: Dict[str, Any] = {}
self._id_token_overrides: dict[str, Any] = {}
def reset_mocks(self) -> None:
self.request.reset_mock()
@@ -222,7 +222,7 @@ class FakeOidcServer:
userinfo: dict,
nonce: Optional[str] = None,
with_sid: bool = False,
) -> Tuple[str, FakeAuthorizationGrant]:
) -> tuple[str, FakeAuthorizationGrant]:
"""Start an authorization request, and get back the code to use on the authorization endpoint."""
code = random_string(10)
sid = None
@@ -242,7 +242,7 @@ class FakeOidcServer:
return code, grant
def exchange_code(self, code: str) -> Optional[Dict[str, Any]]:
def exchange_code(self, code: str) -> Optional[dict[str, Any]]:
grant = self._authorization_grants.pop(code, None)
if grant is None:
return None
@@ -269,7 +269,7 @@ class FakeOidcServer:
metadata: bool = False,
token: bool = False,
userinfo: bool = False,
) -> ContextManager[Dict[str, Mock]]:
) -> ContextManager[dict[str, Mock]]:
"""A context which makes a set of endpoints return a 500 error.
Args:
@@ -356,7 +356,7 @@ class FakeOidcServer:
return FakeResponse.json(payload=user_info)
def _post_token_handler(self, params: Dict[str, List[str]]) -> IResponse:
def _post_token_handler(self, params: dict[str, list[str]]) -> IResponse:
"""Handles requests to the token endpoint."""
code = params.get("code", [])