From cb2cd00cd17492207aad2280b40455fe0aa5a034 Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Mon, 23 Dec 2024 22:02:58 +1300 Subject: [PATCH] cache plugins: use f-strings (#9320) * cache plugins: use f-strings * add changelog frag --- changelogs/fragments/9320-fstr-cache-plugins.yml | 3 +++ plugins/cache/memcached.py | 2 +- plugins/cache/redis.py | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/9320-fstr-cache-plugins.yml diff --git a/changelogs/fragments/9320-fstr-cache-plugins.yml b/changelogs/fragments/9320-fstr-cache-plugins.yml new file mode 100644 index 0000000000..cc1aa6ea2e --- /dev/null +++ b/changelogs/fragments/9320-fstr-cache-plugins.yml @@ -0,0 +1,3 @@ +minor_changes: + - memcached cache plugin - use f-strings instead of interpolations or ``format`` (https://github.com/ansible-collections/community.general/pull/9320). + - redis cache plugin - use f-strings instead of interpolations or ``format`` (https://github.com/ansible-collections/community.general/pull/9320). diff --git a/plugins/cache/memcached.py b/plugins/cache/memcached.py index 93131172c5..a70c3cb121 100644 --- a/plugins/cache/memcached.py +++ b/plugins/cache/memcached.py @@ -191,7 +191,7 @@ class CacheModule(BaseCacheModule): self._keys = CacheModuleKeys(self._db, self._db.get(CacheModuleKeys.PREFIX) or []) def _make_key(self, key): - return "{0}{1}".format(self._prefix, key) + return f"{self._prefix}{key}" def _expire_keys(self): if self._timeout > 0: diff --git a/plugins/cache/redis.py b/plugins/cache/redis.py index f96aafaa84..aa0243b9dd 100644 --- a/plugins/cache/redis.py +++ b/plugins/cache/redis.py @@ -131,7 +131,7 @@ class CacheModule(BaseCacheModule): connection = self._parse_connection(self.re_url_conn, uri) self._db = StrictRedis(*connection, **kw) - display.vv('Redis connection: %s' % self._db) + display.vv(f'Redis connection: {self._db}') @staticmethod def _parse_connection(re_patt, uri): @@ -164,12 +164,12 @@ class CacheModule(BaseCacheModule): pass # password is optional sentinels = [self._parse_connection(self.re_sent_conn, shost) for shost in connections] - display.vv('\nUsing redis sentinels: %s' % sentinels) + display.vv(f'\nUsing redis sentinels: {sentinels}') scon = Sentinel(sentinels, **kw) try: return scon.master_for(self._sentinel_service_name, socket_timeout=0.2) except Exception as exc: - raise AnsibleError('Could not connect to redis sentinel: %s' % to_native(exc)) + raise AnsibleError(f'Could not connect to redis sentinel: {to_native(exc)}') def _make_key(self, key): return self._prefix + key