-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add type hints to synapse/storage/databases/main/e2e_room_keys.py
#11549
Changes from all commits
f3fbbed
4e6f213
bd26484
3d599bc
3cbc0e9
6772c87
320ccc1
d716c34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add missing type hints to storage classes. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -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]]] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+64
to
+66
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous annotation was incorrect. The caller and tests expect a JsonDict to be returned: synapse/synapse/rest/client/room_keys.py Lines 199 to 223 in 0cc3bf9
synapse/tests/handlers/test_e2e_room_keys.py Lines 404 to 409 in 0cc3bf9
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any idea why mypy didn't spot this? I guess the tests aren't checked, but I'd hope room_keys was
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting! I think @H-Shay is taking a look at annotating that file, maybe this will show up the problem. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """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. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -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) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.