Another batch of type annotations (#12726)

This commit is contained in:
David Robertson 2022-05-13 12:35:31 +01:00 committed by GitHub
parent 39bed28b28
commit aec69d2481
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 144 additions and 79 deletions

View file

@ -12,20 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from types import TracebackType
from typing import (
TYPE_CHECKING,
Any,
AsyncContextManager,
Awaitable,
Callable,
Dict,
Iterable,
List,
Optional,
Type,
)
import attr
from synapse.metrics.background_process_metrics import run_as_background_process
from synapse.storage.types import Connection
from synapse.storage.types import Connection, Cursor
from synapse.types import JsonDict
from synapse.util import Clock, json_encoder
@ -74,7 +78,12 @@ class _BackgroundUpdateContextManager:
return self._update_duration_ms
async def __aexit__(self, *exc) -> None:
async def __aexit__(
self,
exc_type: Optional[Type[BaseException]],
exc: Optional[BaseException],
tb: Optional[TracebackType],
) -> None:
pass
@ -352,7 +361,7 @@ class BackgroundUpdater:
True if we have finished running all the background updates, otherwise False
"""
def get_background_updates_txn(txn):
def get_background_updates_txn(txn: Cursor) -> List[Dict[str, Any]]:
txn.execute(
"""
SELECT update_name, depends_on FROM background_updates
@ -469,7 +478,7 @@ class BackgroundUpdater:
self,
update_name: str,
update_handler: Callable[[JsonDict, int], Awaitable[int]],
):
) -> None:
"""Register a handler for doing a background update.
The handler should take two arguments:
@ -603,7 +612,7 @@ class BackgroundUpdater:
else:
runner = create_index_sqlite
async def updater(progress, batch_size):
async def updater(progress: JsonDict, batch_size: int) -> int:
if runner is not None:
logger.info("Adding index %s to %s", index_name, table)
await self.db_pool.runWithConnection(runner)