From b4f59b771cc8a89976cbea8c889758c132d405d0 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Mon, 21 Nov 2022 22:20:19 -0100 Subject: [PATCH] Techdebt: Replace string-format with f-strings (#5695) --- moto/utilities/distutils_version.py | 4 ++-- moto/utilities/paginator.py | 8 ++------ moto/xray/exceptions.py | 2 +- requirements-dev.txt | 1 + tests/test_dynamodb/test_dynamodb.py | 2 +- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/moto/utilities/distutils_version.py b/moto/utilities/distutils_version.py index 280dff174..12d6702bd 100644 --- a/moto/utilities/distutils_version.py +++ b/moto/utilities/distutils_version.py @@ -45,7 +45,7 @@ class Version: self.parse(vstring) def __repr__(self): - return "%s ('%s')" % (self.__class__.__name__, str(self)) + return f"{self.__class__.__name__} ('{self}')" def __eq__(self, other): c = self._cmp(other) @@ -217,7 +217,7 @@ class LooseVersion(Version): return self.vstring def __repr__(self): - return "LooseVersion ('%s')" % str(self) + return f"LooseVersion ('{self}')" def _cmp(self, other): if isinstance(other, str): diff --git a/moto/utilities/paginator.py b/moto/utilities/paginator.py index 983bc8ef4..2a07f763e 100644 --- a/moto/utilities/paginator.py +++ b/moto/utilities/paginator.py @@ -20,9 +20,7 @@ def paginate( model = pagination_model pagination_config = model.get(method) if not pagination_config: - raise ValueError( - "No pagination config for backend method: {}".format(method) - ) + raise ValueError(f"No pagination config for backend method: {method}") # Get the pagination arguments, to be used by the paginator next_token_name = pagination_config.get("input_token", "next_token") limit_name = pagination_config.get("limit_key") @@ -100,9 +98,7 @@ class Paginator(object): self._raise_exception_if_required(next_token) return None if next_token.get("parameterChecksum") != self._param_checksum: - raise InvalidToken( - "Input inconsistent with page token: {}".format(str(next_token)) - ) + raise InvalidToken(f"Input inconsistent with page token: {str(next_token)}") return next_token def _raise_exception_if_required(self, token): diff --git a/moto/xray/exceptions.py b/moto/xray/exceptions.py index 2449cb45d..5462bcf33 100644 --- a/moto/xray/exceptions.py +++ b/moto/xray/exceptions.py @@ -5,7 +5,7 @@ class BadSegmentException(Exception): self.message = message def __repr__(self): - return "".format("-".join([self.id, self.code, self.message])) + return f"" def to_dict(self): result = {} diff --git a/requirements-dev.txt b/requirements-dev.txt index 155063c2f..852da3205 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,6 +4,7 @@ black==22.3.0 flake8==4.0.1 flake8-print +flake8-use-fstring click inflection lxml diff --git a/tests/test_dynamodb/test_dynamodb.py b/tests/test_dynamodb/test_dynamodb.py index ce2229572..1a78618b3 100644 --- a/tests/test_dynamodb/test_dynamodb.py +++ b/tests/test_dynamodb/test_dynamodb.py @@ -3914,7 +3914,7 @@ def test_transact_write_items_put_conditional_expressions_return_values_on_condi { "Put": { "Item": { - "id": {"S": "foo{}".format(str(i))}, + "id": {"S": f"foo{i}"}, "foo": {"S": "bar"}, }, "TableName": "test-table",