Skip to content

Commit

Permalink
Convert str.format() and % formatting to f-strings (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
eforgacs authored Aug 28, 2021
1 parent ea1c10b commit 716717f
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion server/gameconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion server/games/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions server/lobbyconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/matchmaker/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
"""
Expand Down
2 changes: 1 addition & 1 deletion server/servercontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions tests/integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 1 addition & 3 deletions tests/integration_tests/test_message_queue_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 716717f

Please sign in to comment.