7171 PsycopgEngine ,
7272 Sqlite3Engine ,
7373)
74+ from synapse .storage .engines ._base import IsolationLevel
7475from synapse .storage .types import Connection , Cursor , SQLQueryParameters
7576from synapse .types import StrCollection
7677from synapse .util .async_helpers import delay_cancellation
@@ -408,7 +409,7 @@ def execute_values(
408409 values : Collection [Iterable [Any ]],
409410 template : Optional [str ] = None ,
410411 fetch : bool = True ,
411- ) -> List [Tuple ]:
412+ ) -> Iterable [Tuple ]:
412413 """Corresponds to psycopg2.extras.execute_values. Only available when
413414 using postgres.
414415
@@ -453,7 +454,7 @@ def execute_values(
453454 def f (
454455 the_sql : str , the_args : Sequence [Sequence [Any ]]
455456 ) -> Iterable [Tuple [Any , ...]]:
456- with self .txn .copy (the_sql , the_args ) as copy :
457+ with self .txn .copy (the_sql , the_args ) as copy : # type: ignore[attr-defined]
457458 yield from copy .rows ()
458459
459460 # Flatten the values.
@@ -468,7 +469,7 @@ def copy_write(
468469 def f (
469470 the_sql : str , the_args : Iterable [Any ], the_values : Iterable [Iterable [Any ]]
470471 ) -> None :
471- with self .txn .copy (the_sql , the_args ) as copy :
472+ with self .txn .copy (the_sql , the_args ) as copy : # type: ignore[attr-defined]
472473 for record in the_values :
473474 copy .write_row (record )
474475
@@ -504,12 +505,6 @@ def executescript(self, sql: str) -> None:
504505
505506 def _make_sql_one_line (self , sql : str ) -> str :
506507 "Strip newlines out of SQL so that the loggers in the DB are on one line"
507- if isinstance (self .database_engine , PsycopgEngine ):
508- import psycopg .sql
509-
510- if isinstance (sql , psycopg .sql .Composed ):
511- return sql .as_string (None )
512-
513508 return " " .join (line .strip () for line in sql .splitlines () if line .strip ())
514509
515510 def _do_execute (
@@ -933,7 +928,7 @@ async def runInteraction(
933928 func : Callable [..., R ],
934929 * args : Any ,
935930 db_autocommit : bool = False ,
936- isolation_level : Optional [int ] = None ,
931+ isolation_level : Optional [IsolationLevel ] = None ,
937932 ** kwargs : Any ,
938933 ) -> R :
939934 """Starts a transaction on the database and runs a given function
@@ -1015,7 +1010,7 @@ async def runWithConnection(
10151010 func : Callable [Concatenate [LoggingDatabaseConnection , P ], R ],
10161011 * args : Any ,
10171012 db_autocommit : bool = False ,
1018- isolation_level : Optional [int ] = None ,
1013+ isolation_level : Optional [IsolationLevel ] = None ,
10191014 ** kwargs : Any ,
10201015 ) -> R :
10211016 """Wraps the .runWithConnection() method on the underlying db_pool.
@@ -2421,7 +2416,7 @@ def simple_delete_many_batch_txn(
24212416 txn : LoggingTransaction ,
24222417 table : str ,
24232418 keys : Collection [str ],
2424- values : Iterable [Iterable [Any ]],
2419+ values : Sequence [Iterable [Any ]],
24252420 ) -> None :
24262421 """Executes a DELETE query on the named table.
24272422
0 commit comments