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

Get db signatures file to pass mypy #11312

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/11312.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add type hints to storage classes.
1 change: 0 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ exclude = (?x)
|synapse/storage/databases/main/room_batch.py
|synapse/storage/databases/main/roommember.py
|synapse/storage/databases/main/search.py
|synapse/storage/databases/main/signatures.py
|synapse/storage/databases/main/state.py
|synapse/storage/databases/main/state_deltas.py
|synapse/storage/databases/main/stats.py
Expand Down
12 changes: 5 additions & 7 deletions synapse/events/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,12 @@ async def build(
)

format_version = self.room_version.event_format
# The types of auth/prev events changes between event versions.
prev_events: Union[List[str], List[Tuple[str, Dict[str, str]]]]
auth_events: Union[List[str], List[Tuple[str, Dict[str, str]]]]
if format_version == EventFormatVersions.V1:
# The types of auth/prev events changes between event versions.
auth_events: Union[
List[str], List[Tuple[str, Dict[str, str]]]
] = await self._store.add_event_hashes(auth_event_ids)
prev_events: Union[
List[str], List[Tuple[str, Dict[str, str]]]
] = await self._store.add_event_hashes(prev_event_ids)
auth_events = await self._store.add_event_hashes(auth_event_ids)
prev_events = await self._store.add_event_hashes(prev_event_ids)
Comment on lines +131 to +136
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this changing anything or just moving the types up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just moving the types up. I was confused because add_event_hashes returns the List[Tuple[...]], which I thought made the union unnecessary. But in the else branch, both event lists are List[str]. I hoped that moving it up would make this clearer.

else:
auth_events = auth_event_ids
prev_events = prev_event_ids
Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/databases/main/signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ async def add_event_hashes(
A list of tuples of event ID and a mapping of algorithm to base-64 encoded hash.
"""
hashes = await self.get_event_reference_hashes(event_ids)
hashes = {
encoded_hashes = {
e_id: {k: encode_base64(v) for k, v in h.items() if k == "sha256"}
for e_id, h in hashes.items()
}

return list(hashes.items())
return list(encoded_hashes.items())

def _get_event_reference_hashes_txn(
self, txn: Cursor, event_id: str
Expand Down