Skip to content

Commit 523b3c0

Browse files
committed
lint and format strings
1 parent fd3e781 commit 523b3c0

File tree

5 files changed

+22
-38
lines changed

5 files changed

+22
-38
lines changed

fastapi_plugins/_redis.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,9 @@ def get_redis_address(self) -> str:
6767
if self.redis_url:
6868
return self.redis_url
6969
elif self.redis_db:
70-
return 'redis://%s:%s/%s' % (
71-
self.redis_host,
72-
self.redis_port,
73-
self.redis_db
74-
)
70+
return f'redis://{self.redis_host}:{self.redis_port}/{self.redis_db}'
7571
else:
76-
return 'redis://%s:%s' % (self.redis_host, self.redis_port)
72+
return f'redis://{self.redis_host}:{self.redis_port}'
7773

7874
# TODO: xxx the customer validator does not work
7975
def get_sentinels(self) -> typing.List:
@@ -88,11 +84,7 @@ def get_sentinels(self) -> typing.List:
8884
if _conn.strip()
8985
]
9086
except Exception as e:
91-
raise RuntimeError(
92-
'bad sentinels string :: %s :: %s :: %s' % (
93-
type(e), str(e), self.redis_sentinels
94-
)
95-
)
87+
raise RuntimeError(f'bad sentinels string :: {type(e)} :: {str(e)} :: {self.redis_sentinels}') # noqa
9688
else:
9789
return []
9890

@@ -101,7 +93,7 @@ class RedisPlugin(Plugin, ControlHealthMixin):
10193
DEFAULT_CONFIG_CLASS = RedisSettings
10294

10395
def _on_init(self) -> None:
104-
self.redis: typing.Union[aioredis.Redis, aioredis_sentinel.Sentinel] = None # noqa E501
96+
self.redis: typing.Union[aioredis.Redis, aioredis_sentinel.Sentinel] = None
10597

10698
async def _on_call(self) -> typing.Any:
10799
if self.redis is None:
@@ -114,9 +106,7 @@ async def _on_call(self) -> typing.Any:
114106
elif self.config.redis_type == RedisType.fakeredis:
115107
conn = self.redis
116108
else:
117-
raise NotImplementedError(
118-
'Redis type %s is not implemented' % self.config.redis_type
119-
)
109+
raise NotImplementedError(f'Redis type {self.config.redis_type} is not implemented') # noqa
120110
#
121111
conn.TTL = self.config.redis_ttl
122112
return conn
@@ -163,9 +153,7 @@ async def init(self):
163153
address = self.config.get_sentinels()
164154
method = aioredis_sentinel.Sentinel
165155
else:
166-
raise NotImplementedError(
167-
'Redis type %s is not implemented' % self.config.redis_type
168-
)
156+
raise NotImplementedError(f'Redis type {self.config.redis_type} is not implemented') # noqa
169157
#
170158
if not address:
171159
raise ValueError('Redis address is empty')
@@ -202,11 +190,9 @@ async def ping(self):
202190
elif self.config.redis_type == RedisType.fakeredis:
203191
return await self.redis.ping()
204192
elif self.config.redis_type == RedisType.sentinel:
205-
return await self.redis.master_for(self.config.redis_sentinel_master).ping() # noqa E501
193+
return await self.redis.master_for(self.config.redis_sentinel_master).ping()
206194
else:
207-
raise NotImplementedError(
208-
'Redis type %s.ping() is not implemented' % self.config.redis_type # noqa E501
209-
)
195+
raise NotImplementedError(f'Redis type {self.config.redis_type}.ping() is not implemented') # noqa
210196

211197

212198
redis_plugin = RedisPlugin()

fastapi_plugins/logger.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def format_line(self, extra: typing.Dict) -> str:
7272
outarr = []
7373
for k, v in extra.items():
7474
if v is None:
75-
outarr.append('%s=' % k)
75+
outarr.append(f'{k}=')
7676
continue
7777
if isinstance(v, bool):
7878
v = 'true' if v else 'false'
@@ -82,15 +82,15 @@ def format_line(self, extra: typing.Dict) -> str:
8282
if isinstance(v, (dict, object)):
8383
v = str(v)
8484
v = '"%s"' % v.replace('"', '\\"')
85-
outarr.append('%s=%s' % (k, v))
85+
outarr.append(f'{k}={v}')
8686
return ' '.join(outarr)
8787

8888
def format(self, record):
8989
return ' '.join(
9090
[
91-
'at=%s' % record.levelname,
91+
f'at={record.levelname}',
9292
'msg="%s"' % record.getMessage().replace('"', '\\"'),
93-
'process=%s' % record.processName,
93+
f'process={record.processName}',
9494
self.format_line(getattr(record, 'context', {})),
9595
]
9696
).strip()

fastapi_plugins/memcached.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ async def _init_memcached():
9494
try:
9595
await _init_memcached()
9696
except Exception as e:
97-
raise MemcachedError(
98-
'Memcached initialization failed :: %s :: %s' % (type(e), e)
99-
)
97+
raise MemcachedError(f'Memcached initialization failed :: {type(e)} :: {str(e)}') # noqa
10098

10199
async def terminate(self):
102100
self.config = None
@@ -122,4 +120,4 @@ async def depends_memcached(
122120
return await conn.app.state.MEMCACHED()
123121

124122

125-
TMemcachedPlugin = Annotated[MemcachedClient, fastapi.Depends(depends_memcached)] # noqa E501
123+
TMemcachedPlugin = Annotated[MemcachedClient, fastapi.Depends(depends_memcached)]

fastapi_plugins/scheduler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
]
2424
__author__ = 'madkote <madkote(at)bluewin.ch>'
2525
__version__ = '.'.join(str(x) for x in VERSION)
26-
__copyright__ = 'Copyright 2021, madkote'
26+
__copyright__ = 'Copyright 2025, madkote'
2727

2828

2929
class SchedulerError(PluginError):
@@ -139,4 +139,4 @@ async def depends_scheduler(
139139
return await conn.app.state.AIOJOBS_SCHEDULER()
140140

141141

142-
TSchedulerPlugin = Annotated[aiojobs.Scheduler, fastapi.Depends(depends_scheduler)] # noqa E501
142+
TSchedulerPlugin = Annotated[aiojobs.Scheduler, fastapi.Depends(depends_scheduler)]

fastapi_plugins/settings.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
]
3535
__author__ = 'madkote <madkote(at)bluewin.ch>'
3636
__version__ = '.'.join(str(x) for x in VERSION)
37-
__copyright__ = 'Copyright 2021, madkote RES'
37+
__copyright__ = 'Copyright 2025, madkote RES'
3838

3939
DEFAULT_CONFIG_ENVVAR: str = 'CONFIG_NAME'
4040
DEFAULT_CONFIG_NAME: str = 'docker'
@@ -65,9 +65,9 @@ def reset(self) -> None:
6565

6666
def get_config(
6767
self,
68-
config_or_name: typing.Union[str, pydantic_settings.BaseSettings]=None, # noqa E501
69-
config_name_default: str=DEFAULT_CONFIG_NAME,
70-
config_name_envvar: str=DEFAULT_CONFIG_ENVVAR
68+
config_or_name: typing.Union[str, pydantic_settings.BaseSettings] = None,
69+
config_name_default: str = DEFAULT_CONFIG_NAME,
70+
config_name_envvar: str = DEFAULT_CONFIG_ENVVAR
7171
) -> pydantic_settings.BaseSettings:
7272
if isinstance(config_or_name, pydantic_settings.BaseSettings):
7373
return config_or_name
@@ -80,7 +80,7 @@ def get_config(
8080
default=config_or_name
8181
)
8282
if config_or_name not in self._settings_map:
83-
raise ConfigError('Unknown configuration "%s"' % config_or_name)
83+
raise ConfigError(f'Unknown configuration "{config_or_name}"')
8484
return self._settings_map[config_or_name]()
8585

8686

@@ -190,4 +190,4 @@ async def depends_config(
190190
return await conn.app.state.PLUGIN_CONFIG()
191191

192192

193-
TConfigPlugin = Annotated[pydantic_settings.BaseSettings, fastapi.Depends(depends_config)] # noqa E501
193+
TConfigPlugin = Annotated[pydantic_settings.BaseSettings, fastapi.Depends(depends_config)]

0 commit comments

Comments
 (0)