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

Commit 5562ce6

Browse files
author
David Robertson
authored
Get directory db file to pass mypy (#11339)
1 parent 6f862c5 commit 5562ce6

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

changelog.d/11339.misc

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

mypy.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ exclude = (?x)
2828
|synapse/storage/databases/main/account_data.py
2929
|synapse/storage/databases/main/cache.py
3030
|synapse/storage/databases/main/devices.py
31-
|synapse/storage/databases/main/directory.py
3231
|synapse/storage/databases/main/e2e_room_keys.py
3332
|synapse/storage/databases/main/end_to_end_keys.py
3433
|synapse/storage/databases/main/event_federation.py
@@ -177,6 +176,9 @@ disallow_untyped_defs = True
177176
[mypy-synapse.storage.databases.main.client_ips]
178177
disallow_untyped_defs = True
179178

179+
[mypy-synapse.storage.databases.main.directory]
180+
disallow_untyped_defs = True
181+
180182
[mypy-synapse.storage.databases.main.room_batch]
181183
disallow_untyped_defs = True
182184

synapse/storage/databases/main/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ def __init__(self, database: DatabasePool, db_conn, hs: "HomeServer"):
154154
db_conn, "local_group_updates", "stream_id"
155155
)
156156

157+
self._cache_id_gen: Optional[MultiWriterIdGenerator]
157158
if isinstance(self.database_engine, PostgresEngine):
158159
# We set the `writers` to an empty list here as we don't care about
159160
# missing updates over restarts, as we'll not have anything in our

synapse/storage/databases/main/directory.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
# limitations under the License.
1414

1515
from collections import namedtuple
16-
from typing import Iterable, List, Optional
16+
from typing import Iterable, List, Optional, Tuple
1717

1818
from synapse.api.errors import SynapseError
19-
from synapse.storage._base import SQLBaseStore
2019
from synapse.storage.database import LoggingTransaction
20+
from synapse.storage.databases.main import CacheInvalidationWorkerStore
2121
from synapse.types import RoomAlias
2222
from synapse.util.caches.descriptors import cached
2323

2424
RoomAliasMapping = namedtuple("RoomAliasMapping", ("room_id", "room_alias", "servers"))
2525

2626

27-
class DirectoryWorkerStore(SQLBaseStore):
27+
class DirectoryWorkerStore(CacheInvalidationWorkerStore):
2828
async def get_association_from_room_alias(
2929
self, room_alias: RoomAlias
3030
) -> Optional[RoomAliasMapping]:
@@ -92,7 +92,7 @@ async def create_room_alias_association(
9292
creator: Optional user_id of creator.
9393
"""
9494

95-
def alias_txn(txn):
95+
def alias_txn(txn: LoggingTransaction) -> None:
9696
self.db_pool.simple_insert_txn(
9797
txn,
9898
"room_aliases",
@@ -176,9 +176,9 @@ async def update_aliases_for_room(
176176
If None, the creator will be left unchanged.
177177
"""
178178

179-
def _update_aliases_for_room_txn(txn):
179+
def _update_aliases_for_room_txn(txn: LoggingTransaction) -> None:
180180
update_creator_sql = ""
181-
sql_params = (new_room_id, old_room_id)
181+
sql_params: Tuple[str, ...] = (new_room_id, old_room_id)
182182
if creator:
183183
update_creator_sql = ", creator = ?"
184184
sql_params = (new_room_id, creator, old_room_id)

0 commit comments

Comments
 (0)