1414# limitations under the License.
1515import logging
1616import re
17- from typing import TYPE_CHECKING , List , Optional , Pattern , Tuple
17+ from typing import TYPE_CHECKING , Any , Dict , List , Optional , Pattern , Tuple
1818
1919from synapse .appservice import (
2020 ApplicationService ,
2626from synapse .config .appservice import load_appservices
2727from synapse .events import EventBase
2828from synapse .storage ._base import db_to_json
29- from synapse .storage .database import DatabasePool , LoggingDatabaseConnection
29+ from synapse .storage .database import (
30+ DatabasePool ,
31+ LoggingDatabaseConnection ,
32+ LoggingTransaction ,
33+ )
3034from synapse .storage .databases .main .events_worker import EventsWorkerStore
3135from synapse .storage .databases .main .roommember import RoomMemberWorkerStore
3236from synapse .storage .types import Cursor
@@ -92,7 +96,7 @@ def get_max_as_txn_id(txn: Cursor) -> int:
9296
9397 super ().__init__ (database , db_conn , hs )
9498
95- def get_app_services (self ):
99+ def get_app_services (self ) -> List [ ApplicationService ] :
96100 return self .services_cache
97101
98102 def get_if_app_services_interested_in_user (self , user_id : str ) -> bool :
@@ -256,7 +260,7 @@ async def create_appservice_txn(
256260 A new transaction.
257261 """
258262
259- def _create_appservice_txn (txn ) :
263+ def _create_appservice_txn (txn : LoggingTransaction ) -> AppServiceTransaction :
260264 new_txn_id = self ._as_txn_seq_gen .get_next_id_txn (txn )
261265
262266 # Insert new txn into txn table
@@ -291,7 +295,7 @@ async def complete_appservice_txn(
291295 service: The application service which was sent this transaction.
292296 """
293297
294- def _complete_appservice_txn (txn ) :
298+ def _complete_appservice_txn (txn : LoggingTransaction ) -> None :
295299 # Set current txn_id for AS to 'txn_id'
296300 self .db_pool .simple_upsert_txn (
297301 txn ,
@@ -322,7 +326,9 @@ async def get_oldest_unsent_txn(
322326 An AppServiceTransaction or None.
323327 """
324328
325- def _get_oldest_unsent_txn (txn ):
329+ def _get_oldest_unsent_txn (
330+ txn : LoggingTransaction ,
331+ ) -> Optional [Dict [str , Any ]]:
326332 # Monotonically increasing txn ids, so just select the smallest
327333 # one in the txns table (we delete them when they are sent)
328334 txn .execute (
@@ -364,7 +370,7 @@ def _get_oldest_unsent_txn(txn):
364370 )
365371
366372 async def set_appservice_last_pos (self , pos : int ) -> None :
367- def set_appservice_last_pos_txn (txn ) :
373+ def set_appservice_last_pos_txn (txn : LoggingTransaction ) -> None :
368374 txn .execute (
369375 "UPDATE appservice_stream_position SET stream_ordering = ?" , (pos ,)
370376 )
@@ -378,7 +384,9 @@ async def get_new_events_for_appservice(
378384 ) -> Tuple [int , List [EventBase ]]:
379385 """Get all new events for an appservice"""
380386
381- def get_new_events_for_appservice_txn (txn ):
387+ def get_new_events_for_appservice_txn (
388+ txn : LoggingTransaction ,
389+ ) -> Tuple [int , List [str ]]:
382390 sql = (
383391 "SELECT e.stream_ordering, e.event_id"
384392 " FROM events AS e"
@@ -416,7 +424,7 @@ async def get_type_stream_id_for_appservice(
416424 % (type ,)
417425 )
418426
419- def get_type_stream_id_for_appservice_txn (txn ) :
427+ def get_type_stream_id_for_appservice_txn (txn : LoggingTransaction ) -> int :
420428 stream_id_type = "%s_stream_id" % type
421429 txn .execute (
422430 # We do NOT want to escape `stream_id_type`.
@@ -444,7 +452,7 @@ async def set_appservice_stream_type_pos(
444452 % (stream_type ,)
445453 )
446454
447- def set_appservice_stream_type_pos_txn (txn ) :
455+ def set_appservice_stream_type_pos_txn (txn : LoggingTransaction ) -> None :
448456 stream_id_type = "%s_stream_id" % stream_type
449457 txn .execute (
450458 "UPDATE application_services_state SET %s = ? WHERE as_id=?"
0 commit comments