From 0cd182f296ce44dbaafc9a56f9af2183d21a9443 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Fri, 8 Apr 2022 15:00:12 +0100 Subject: Make `synapse._scripts` pass typechecks (#12421) --- synapse/_scripts/update_synapse_database.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'synapse/_scripts/update_synapse_database.py') diff --git a/synapse/_scripts/update_synapse_database.py b/synapse/_scripts/update_synapse_database.py index f43676afaa..736f58836d 100755 --- a/synapse/_scripts/update_synapse_database.py +++ b/synapse/_scripts/update_synapse_database.py @@ -16,22 +16,27 @@ import argparse import logging import sys +from typing import cast import yaml from matrix_common.versionstring import get_distribution_version_string -from twisted.internet import defer, reactor +from twisted.internet import defer, reactor as reactor_ from synapse.config.homeserver import HomeServerConfig from synapse.metrics.background_process_metrics import run_as_background_process from synapse.server import HomeServer from synapse.storage import DataStore +from synapse.types import ISynapseReactor +# Cast safety: Twisted does some naughty magic which replaces the +# twisted.internet.reactor module with a Reactor instance at runtime. +reactor = cast(ISynapseReactor, reactor_) logger = logging.getLogger("update_database") class MockHomeserver(HomeServer): - DATASTORE_CLASS = DataStore + DATASTORE_CLASS = DataStore # type: ignore [assignment] def __init__(self, config, **kwargs): super(MockHomeserver, self).__init__( @@ -85,12 +90,10 @@ def main(): args = parser.parse_args() - logging_config = { - "level": logging.DEBUG if args.v else logging.INFO, - "format": "%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(message)s", - } - - logging.basicConfig(**logging_config) + logging.basicConfig( + level=logging.DEBUG if args.v else logging.INFO, + format="%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(message)s", + ) # Load, process and sanity-check the config. hs_config = yaml.safe_load(args.database_config) -- cgit 1.4.1