Get directory db file to pass mypy (#11339)

This commit is contained in:
David Robertson 2021-11-15 12:59:05 +00:00 committed by GitHub
parent 6f862c5c28
commit 5562ce6a53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 7 deletions

1
changelog.d/11339.misc Normal file
View file

@ -0,0 +1 @@
Add type hints to storage classes.

View file

@ -28,7 +28,6 @@ exclude = (?x)
|synapse/storage/databases/main/account_data.py |synapse/storage/databases/main/account_data.py
|synapse/storage/databases/main/cache.py |synapse/storage/databases/main/cache.py
|synapse/storage/databases/main/devices.py |synapse/storage/databases/main/devices.py
|synapse/storage/databases/main/directory.py
|synapse/storage/databases/main/e2e_room_keys.py |synapse/storage/databases/main/e2e_room_keys.py
|synapse/storage/databases/main/end_to_end_keys.py |synapse/storage/databases/main/end_to_end_keys.py
|synapse/storage/databases/main/event_federation.py |synapse/storage/databases/main/event_federation.py
@ -177,6 +176,9 @@ disallow_untyped_defs = True
[mypy-synapse.storage.databases.main.client_ips] [mypy-synapse.storage.databases.main.client_ips]
disallow_untyped_defs = True disallow_untyped_defs = True
[mypy-synapse.storage.databases.main.directory]
disallow_untyped_defs = True
[mypy-synapse.storage.databases.main.room_batch] [mypy-synapse.storage.databases.main.room_batch]
disallow_untyped_defs = True disallow_untyped_defs = True

View file

@ -154,6 +154,7 @@ class DataStore(
db_conn, "local_group_updates", "stream_id" db_conn, "local_group_updates", "stream_id"
) )
self._cache_id_gen: Optional[MultiWriterIdGenerator]
if isinstance(self.database_engine, PostgresEngine): if isinstance(self.database_engine, PostgresEngine):
# We set the `writers` to an empty list here as we don't care about # We set the `writers` to an empty list here as we don't care about
# missing updates over restarts, as we'll not have anything in our # missing updates over restarts, as we'll not have anything in our

View file

@ -13,18 +13,18 @@
# limitations under the License. # limitations under the License.
from collections import namedtuple from collections import namedtuple
from typing import Iterable, List, Optional from typing import Iterable, List, Optional, Tuple
from synapse.api.errors import SynapseError from synapse.api.errors import SynapseError
from synapse.storage._base import SQLBaseStore
from synapse.storage.database import LoggingTransaction from synapse.storage.database import LoggingTransaction
from synapse.storage.databases.main import CacheInvalidationWorkerStore
from synapse.types import RoomAlias from synapse.types import RoomAlias
from synapse.util.caches.descriptors import cached from synapse.util.caches.descriptors import cached
RoomAliasMapping = namedtuple("RoomAliasMapping", ("room_id", "room_alias", "servers")) RoomAliasMapping = namedtuple("RoomAliasMapping", ("room_id", "room_alias", "servers"))
class DirectoryWorkerStore(SQLBaseStore): class DirectoryWorkerStore(CacheInvalidationWorkerStore):
async def get_association_from_room_alias( async def get_association_from_room_alias(
self, room_alias: RoomAlias self, room_alias: RoomAlias
) -> Optional[RoomAliasMapping]: ) -> Optional[RoomAliasMapping]:
@ -92,7 +92,7 @@ class DirectoryWorkerStore(SQLBaseStore):
creator: Optional user_id of creator. creator: Optional user_id of creator.
""" """
def alias_txn(txn): def alias_txn(txn: LoggingTransaction) -> None:
self.db_pool.simple_insert_txn( self.db_pool.simple_insert_txn(
txn, txn,
"room_aliases", "room_aliases",
@ -176,9 +176,9 @@ class DirectoryStore(DirectoryWorkerStore):
If None, the creator will be left unchanged. If None, the creator will be left unchanged.
""" """
def _update_aliases_for_room_txn(txn): def _update_aliases_for_room_txn(txn: LoggingTransaction) -> None:
update_creator_sql = "" update_creator_sql = ""
sql_params = (new_room_id, old_room_id) sql_params: Tuple[str, ...] = (new_room_id, old_room_id)
if creator: if creator:
update_creator_sql = ", creator = ?" update_creator_sql = ", creator = ?"
sql_params = (new_room_id, creator, old_room_id) sql_params = (new_room_id, creator, old_room_id)