Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit ecfcd9b

Browse files
authored
Add type hints to synapse/storage/databases/main/e2e_room_keys.py (#11549)
1 parent 0147b3d commit ecfcd9b

File tree

6 files changed

+188
-79
lines changed

6 files changed

+188
-79
lines changed

changelog.d/11549.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add missing type hints to storage classes.

mypy.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ exclude = (?x)
2727
|synapse/storage/databases/main/__init__.py
2828
|synapse/storage/databases/main/cache.py
2929
|synapse/storage/databases/main/devices.py
30-
|synapse/storage/databases/main/e2e_room_keys.py
3130
|synapse/storage/databases/main/event_federation.py
3231
|synapse/storage/databases/main/event_push_actions.py
3332
|synapse/storage/databases/main/events_bg_updates.py
@@ -197,6 +196,9 @@ disallow_untyped_defs = True
197196
[mypy-synapse.storage.databases.main.directory]
198197
disallow_untyped_defs = True
199198

199+
[mypy-synapse.storage.databases.main.e2e_room_keys]
200+
disallow_untyped_defs = True
201+
200202
[mypy-synapse.storage.databases.main.end_to_end_keys]
201203
disallow_untyped_defs = True
202204

synapse/handlers/e2e_room_keys.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
# limitations under the License.
1515

1616
import logging
17-
from typing import TYPE_CHECKING, List, Optional
17+
from typing import TYPE_CHECKING, Dict, Optional
18+
19+
from typing_extensions import Literal
1820

1921
from synapse.api.errors import (
2022
Codes,
@@ -24,6 +26,7 @@
2426
SynapseError,
2527
)
2628
from synapse.logging.opentracing import log_kv, trace
29+
from synapse.storage.databases.main.e2e_room_keys import RoomKey
2730
from synapse.types import JsonDict
2831
from synapse.util.async_helpers import Linearizer
2932

@@ -58,7 +61,9 @@ async def get_room_keys(
5861
version: str,
5962
room_id: Optional[str] = None,
6063
session_id: Optional[str] = None,
61-
) -> List[JsonDict]:
64+
) -> Dict[
65+
Literal["rooms"], Dict[str, Dict[Literal["sessions"], Dict[str, RoomKey]]]
66+
]:
6267
"""Bulk get the E2E room keys for a given backup, optionally filtered to a given
6368
room, or a given session.
6469
See EndToEndRoomKeyStore.get_e2e_room_keys for full details.
@@ -72,8 +77,8 @@ async def get_room_keys(
7277
Raises:
7378
NotFoundError: if the backup version does not exist
7479
Returns:
75-
A list of dicts giving the session_data and message metadata for
76-
these room keys.
80+
A dict giving the session_data and message metadata for these room keys.
81+
`{"rooms": {room_id: {"sessions": {session_id: room_key}}}}`
7782
"""
7883

7984
# we deliberately take the lock to get keys so that changing the version
@@ -273,7 +278,7 @@ async def upload_room_keys(
273278

274279
@staticmethod
275280
def _should_replace_room_key(
276-
current_room_key: Optional[JsonDict], room_key: JsonDict
281+
current_room_key: Optional[RoomKey], room_key: RoomKey
277282
) -> bool:
278283
"""
279284
Determine whether to replace a given current_room_key (if any)

0 commit comments

Comments
 (0)