diff --git a/server/gameconnection.py b/server/gameconnection.py index 14d11baa0..66af0db86 100644 --- a/server/gameconnection.py +++ b/server/gameconnection.py @@ -600,7 +600,7 @@ async def on_connection_lost(self): await self.abort() def __str__(self): - return "GameConnection({}, {})".format(self.player, self.game) + return f"GameConnection({self.player}, {self.game})" COMMAND_HANDLERS = { diff --git a/server/games/game.py b/server/games/game.py index c34651916..c9cb8126b 100644 --- a/server/games/game.py +++ b/server/games/game.py @@ -82,7 +82,7 @@ def __init__( self.launched_at = None self.ended = False self._logger = logging.getLogger( - "{}.{}".format(self.__class__.__qualname__, id_) + f"{self.__class__.__qualname__}.{id_}" ) self.id = id_ self.visibility = VisibilityState.PUBLIC diff --git a/server/lobbyconnection.py b/server/lobbyconnection.py index f0f7cbef7..325556300 100644 --- a/server/lobbyconnection.py +++ b/server/lobbyconnection.py @@ -136,7 +136,7 @@ async def ensure_authenticated(self, cmd): "pong", ): metrics.unauth_messages.labels(cmd).inc() - await self.abort("Message invalid for unauthenticated connection: %s" % cmd) + await self.abort(f"Message invalid for unauthenticated connection: {cmd}") return False return True @@ -162,7 +162,7 @@ async def on_message_received(self, message): self._attempted_connectivity_test = True raise ClientError("Your client version is no longer supported. Please update to the newest version: https://faforever.com") - handler = getattr(self, "command_{}".format(cmd)) + handler = getattr(self, f"command_{cmd}") await handler(message) except AuthenticationError as ex: @@ -189,7 +189,7 @@ async def on_message_received(self, message): await self.abort(ex.message) except (KeyError, ValueError) as ex: self._logger.exception(ex) - await self.abort("Garbage command: {}".format(message)) + await self.abort(f"Garbage command: {message}") except ConnectionError as e: # Propagate connection errors to the ServerContext error handler. raise e @@ -513,7 +513,7 @@ async def check_policy_conformity(self, player_id, uid_hash, session, ignore_res ) ) except pymysql.MySQLError as e: - raise ClientError("Banning failed: {}".format(e)) + raise ClientError(f"Banning failed: {e}") return False @@ -1062,7 +1062,7 @@ async def command_modvault(self, message): ui=ui) await self.send(out) except: - self._logger.error("Error handling table_mod row (uid: {})".format(uid), exc_info=True) + self._logger.error(f"Error handling table_mod row (uid: {uid})", exc_info=True) elif type == "like": canLike = True diff --git a/server/matchmaker/search.py b/server/matchmaker/search.py index ce6da04fb..124967953 100644 --- a/server/matchmaker/search.py +++ b/server/matchmaker/search.py @@ -339,7 +339,7 @@ def cancel(self): s.cancel() def __str__(self): - return "CombinedSearch({})".format(",".join(str(s) for s in self.searches)) + return f"CombinedSearch({','.join(str(s) for s in self.searches)})" def get_original_searches(self) -> List[Search]: """ diff --git a/server/servercontext.py b/server/servercontext.py index 0c32fed37..cda19c65a 100644 --- a/server/servercontext.py +++ b/server/servercontext.py @@ -37,7 +37,7 @@ def __init__( self.protocol_class = protocol_class def __repr__(self): - return "ServerContext({})".format(self.name) + return f"ServerContext({self.name})" async def listen(self, host, port): self._logger.debug("%s: listen(%s, %s)", self.name, host, port) diff --git a/tests/integration_tests/conftest.py b/tests/integration_tests/conftest.py index 3e7beea17..34e31a0ad 100644 --- a/tests/integration_tests/conftest.py +++ b/tests/integration_tests/conftest.py @@ -375,11 +375,7 @@ async def connect_and_sign_in( @pytest.fixture async def channel(): connection = await aio_pika.connect( - "amqp://{user}:{password}@localhost/{vhost}".format( - user=config.MQ_USER, - password=config.MQ_PASSWORD, - vhost=config.MQ_VHOST - ) + f"amqp://{config.MQ_USER}:{config.MQ_PASSWORD}@localhost/{config.MQ_VHOST}" ) channel = await connection.channel() diff --git a/tests/integration_tests/test_message_queue_service.py b/tests/integration_tests/test_message_queue_service.py index 5eef0cd75..208d2af4f 100644 --- a/tests/integration_tests/test_message_queue_service.py +++ b/tests/integration_tests/test_message_queue_service.py @@ -18,9 +18,7 @@ def __init__(self): async def initialize(self): self.connection = await aio_pika.connect( - "amqp://{user}:{password}@localhost/{vhost}".format( - user=config.MQ_USER, password=config.MQ_PASSWORD, vhost=config.MQ_VHOST - ) + f"amqp://{config.MQ_USER}:{config.MQ_PASSWORD}@localhost/{config.MQ_VHOST}" ) channel = await self.connection.channel() exchange = await channel.declare_exchange( diff --git a/tests/unit_tests/test_game.py b/tests/unit_tests/test_game.py index 080104d7e..ac0fac93d 100644 --- a/tests/unit_tests/test_game.py +++ b/tests/unit_tests/test_game.py @@ -62,7 +62,7 @@ async def test_initialization(game: Game): async def test_instance_logging(database, game_stats_service): - logger = logging.getLogger("{}.5".format(Game.__qualname__)) + logger = logging.getLogger(f"{Game.__qualname__}.5") logger.debug = mock.Mock() mock_parent = mock.Mock() game = Game(5, database, mock_parent, game_stats_service)