mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-07-27 18:45:16 -04:00
Add some type hints to datastore (#12485)
This commit is contained in:
parent
63ba9ba38b
commit
b76f1a4d5f
12 changed files with 188 additions and 84 deletions
|
@ -15,12 +15,17 @@
|
|||
# limitations under the License.
|
||||
|
||||
import logging
|
||||
from typing import TYPE_CHECKING, List, Optional, Tuple
|
||||
from typing import TYPE_CHECKING, List, Optional, Tuple, cast
|
||||
|
||||
from synapse.config.homeserver import HomeServerConfig
|
||||
from synapse.storage.database import DatabasePool, LoggingDatabaseConnection
|
||||
from synapse.storage.database import (
|
||||
DatabasePool,
|
||||
LoggingDatabaseConnection,
|
||||
LoggingTransaction,
|
||||
)
|
||||
from synapse.storage.databases.main.stats import UserSortOrder
|
||||
from synapse.storage.engines import PostgresEngine
|
||||
from synapse.storage.engines import BaseDatabaseEngine, PostgresEngine
|
||||
from synapse.storage.types import Cursor
|
||||
from synapse.storage.util.id_generators import (
|
||||
IdGenerator,
|
||||
MultiWriterIdGenerator,
|
||||
|
@ -266,7 +271,9 @@ class DataStore(
|
|||
A tuple of a list of mappings from user to information and a count of total users.
|
||||
"""
|
||||
|
||||
def get_users_paginate_txn(txn):
|
||||
def get_users_paginate_txn(
|
||||
txn: LoggingTransaction,
|
||||
) -> Tuple[List[JsonDict], int]:
|
||||
filters = []
|
||||
args = [self.hs.config.server.server_name]
|
||||
|
||||
|
@ -301,7 +308,7 @@ class DataStore(
|
|||
"""
|
||||
sql = "SELECT COUNT(*) as total_users " + sql_base
|
||||
txn.execute(sql, args)
|
||||
count = txn.fetchone()[0]
|
||||
count = cast(Tuple[int], txn.fetchone())[0]
|
||||
|
||||
sql = f"""
|
||||
SELECT name, user_type, is_guest, admin, deactivated, shadow_banned,
|
||||
|
@ -338,7 +345,9 @@ class DataStore(
|
|||
)
|
||||
|
||||
|
||||
def check_database_before_upgrade(cur, database_engine, config: HomeServerConfig):
|
||||
def check_database_before_upgrade(
|
||||
cur: Cursor, database_engine: BaseDatabaseEngine, config: HomeServerConfig
|
||||
) -> None:
|
||||
"""Called before upgrading an existing database to check that it is broadly sane
|
||||
compared with the configuration.
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue