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

Commit

Permalink
Add type hints to synapse/storage/databases/main/e2e_room_keys.py (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
squahtx authored Dec 14, 2021
1 parent 0147b3d commit ecfcd9b
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 79 deletions.
1 change: 1 addition & 0 deletions changelog.d/11549.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add missing type hints to storage classes.
4 changes: 3 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ exclude = (?x)
|synapse/storage/databases/main/__init__.py
|synapse/storage/databases/main/cache.py
|synapse/storage/databases/main/devices.py
|synapse/storage/databases/main/e2e_room_keys.py
|synapse/storage/databases/main/event_federation.py
|synapse/storage/databases/main/event_push_actions.py
|synapse/storage/databases/main/events_bg_updates.py
Expand Down Expand Up @@ -197,6 +196,9 @@ disallow_untyped_defs = True
[mypy-synapse.storage.databases.main.directory]
disallow_untyped_defs = True

[mypy-synapse.storage.databases.main.e2e_room_keys]
disallow_untyped_defs = True

[mypy-synapse.storage.databases.main.end_to_end_keys]
disallow_untyped_defs = True

Expand Down
15 changes: 10 additions & 5 deletions synapse/handlers/e2e_room_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
# limitations under the License.

import logging
from typing import TYPE_CHECKING, List, Optional
from typing import TYPE_CHECKING, Dict, Optional

from typing_extensions import Literal

from synapse.api.errors import (
Codes,
Expand All @@ -24,6 +26,7 @@
SynapseError,
)
from synapse.logging.opentracing import log_kv, trace
from synapse.storage.databases.main.e2e_room_keys import RoomKey
from synapse.types import JsonDict
from synapse.util.async_helpers import Linearizer

Expand Down Expand Up @@ -58,7 +61,9 @@ async def get_room_keys(
version: str,
room_id: Optional[str] = None,
session_id: Optional[str] = None,
) -> List[JsonDict]:
) -> Dict[
Literal["rooms"], Dict[str, Dict[Literal["sessions"], Dict[str, RoomKey]]]
]:
"""Bulk get the E2E room keys for a given backup, optionally filtered to a given
room, or a given session.
See EndToEndRoomKeyStore.get_e2e_room_keys for full details.
Expand All @@ -72,8 +77,8 @@ async def get_room_keys(
Raises:
NotFoundError: if the backup version does not exist
Returns:
A list of dicts giving the session_data and message metadata for
these room keys.
A dict giving the session_data and message metadata for these room keys.
`{"rooms": {room_id: {"sessions": {session_id: room_key}}}}`
"""

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

@staticmethod
def _should_replace_room_key(
current_room_key: Optional[JsonDict], room_key: JsonDict
current_room_key: Optional[RoomKey], room_key: RoomKey
) -> bool:
"""
Determine whether to replace a given current_room_key (if any)
Expand Down
Loading

0 comments on commit ecfcd9b

Please sign in to comment.