Skip to content

Commit 9fa2a1c

Browse files
committed
fix: do not use f-strings in logs
1 parent 9ce2069 commit 9fa2a1c

15 files changed

Lines changed: 77 additions & 77 deletions

File tree

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ dev = [
8282
"pytest-cov>=7.0.0",
8383
"pytest-xdist[psutil]>=3.8.0",
8484
# lint
85-
"ruff>=0.14.5",
85+
"ruff>=0.16.5",
8686
# tests with all python versions
8787
"tox>=4.32.0",
8888
"tox-uv>=1.29.0",
@@ -161,7 +161,8 @@ lint.select = [
161161
"PL", # PyLint checks
162162
"RUF", # Specific to Ruff checks
163163
"FA102", # Future annotations
164-
"UP" # Pyupgrade
164+
"UP", # Pyupgrade
165+
"G", # flake8-logging-format
165166
]
166167
lint.ignore = [
167168
"D105", # Missing docstring in magic method
@@ -172,6 +173,7 @@ lint.ignore = [
172173
"D100", # Missing docstring in public module
173174
"ANN401", # typing.Any are disallowed in `**kwargs
174175
"PLR0913", # Too many arguments for function call
176+
"PLR0917", # Too many positional arguments
175177
"D106" # Missing docstring in public nested class
176178
]
177179
lint.mccabe = { max-complexity = 10 }

taskiq/abc/broker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ def add_middlewares(self, *middlewares: "TaskiqMiddleware") -> None:
177177
for middleware in middlewares:
178178
if not isinstance(middleware, TaskiqMiddleware):
179179
logger.warning(
180-
f"Middleware {middleware} is not an instance of TaskiqMiddleware. "
181-
"Skipping...",
180+
"Middleware %s is not an instance of TaskiqMiddleware. Skipping...",
181+
middleware,
182182
)
183183
continue
184184
middleware.set_broker(self)
@@ -464,8 +464,8 @@ def with_middlewares(
464464
for middleware in middlewares:
465465
if not isinstance(middleware, TaskiqMiddleware):
466466
logger.warning(
467-
f"Middleware {middleware} is not an instance of TaskiqMiddleware. "
468-
"Skipping...",
467+
"Middleware %s is not an instance of TaskiqMiddleware. Skipping...",
468+
middleware,
469469
)
470470
continue
471471
middleware.set_broker(self)

taskiq/abc/middleware.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def set_broker(self, broker: "AsyncBroker") -> None:
2424

2525
def startup(
2626
self,
27-
) -> Union[None, Coroutine[Any, Any, None], "CoroutineType[Any, Any, None]"]:
27+
) -> Union[Coroutine[Any, Any, None], "CoroutineType[Any, Any, None]", None]:
2828
"""
2929
Startup method to perform various action during startup.
3030
@@ -36,7 +36,7 @@ def startup(
3636

3737
def shutdown(
3838
self,
39-
) -> Union[None, Coroutine[Any, Any, None], "CoroutineType[Any, Any, None]"]:
39+
) -> Union[Coroutine[Any, Any, None], "CoroutineType[Any, Any, None]", None]:
4040
"""
4141
Shutdown method to perform various action during shutdown.
4242
@@ -68,7 +68,7 @@ def pre_send(
6868
def post_send(
6969
self,
7070
message: "TaskiqMessage",
71-
) -> Union[None, Coroutine[Any, Any, None], "CoroutineType[Any, Any, None]"]:
71+
) -> Union[Coroutine[Any, Any, None], "CoroutineType[Any, Any, None]", None]:
7272
"""
7373
This hook is executed right after the task is sent.
7474
@@ -101,7 +101,7 @@ def post_execute(
101101
self,
102102
message: "TaskiqMessage",
103103
result: "TaskiqResult[Any]",
104-
) -> Union[None, Coroutine[Any, Any, None], "CoroutineType[Any, Any, None]"]:
104+
) -> Union[Coroutine[Any, Any, None], "CoroutineType[Any, Any, None]", None]:
105105
"""
106106
This hook executes after task is complete.
107107
@@ -116,7 +116,7 @@ def post_save(
116116
self,
117117
message: "TaskiqMessage",
118118
result: "TaskiqResult[Any]",
119-
) -> Union[None, Coroutine[Any, Any, None], "CoroutineType[Any, Any, None]"]:
119+
) -> Union[Coroutine[Any, Any, None], "CoroutineType[Any, Any, None]", None]:
120120
"""
121121
Post save hook.
122122
@@ -132,7 +132,7 @@ def on_error(
132132
message: "TaskiqMessage",
133133
result: "TaskiqResult[Any]",
134134
exception: BaseException,
135-
) -> Union[None, Coroutine[Any, Any, None], "CoroutineType[Any, Any, None]"]:
135+
) -> Union[Coroutine[Any, Any, None], "CoroutineType[Any, Any, None]", None]:
136136
"""
137137
This function is called when exception is found.
138138

taskiq/abc/schedule_source.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async def delete_schedule(self, schedule_id: str) -> None:
5858
def pre_send( # noqa: B027
5959
self,
6060
task: "ScheduledTask",
61-
) -> Union[None, "CoroutineType[Any, Any, None]", Coroutine[Any, Any, None]]:
61+
) -> Union["CoroutineType[Any, Any, None]", Coroutine[Any, Any, None], None]:
6262
"""
6363
Actions to execute before task will be sent to broker.
6464
@@ -71,7 +71,7 @@ def pre_send( # noqa: B027
7171
def post_send( # noqa: B027
7272
self,
7373
task: "ScheduledTask",
74-
) -> Union[None, "CoroutineType[Any, Any, None]", Coroutine[Any, Any, None]]:
74+
) -> Union["CoroutineType[Any, Any, None]", Coroutine[Any, Any, None], None]:
7575
"""
7676
Actions to execute after task was sent to broker.
7777

taskiq/acks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ class AckableMessage(BaseModel):
5454
"""
5555

5656
data: bytes
57-
ack: Callable[[], None | Awaitable[None]]
57+
ack: Callable[[], Awaitable[None] | None]
5858

5959

6060
class AckController:
6161
"""Controls acknowledgement state for a received message."""
6262

63-
def __init__(self, ack: Callable[[], None | Awaitable[None]] | None) -> None:
63+
def __init__(self, ack: Callable[[], Awaitable[None] | None] | None) -> None:
6464
self._ack = ack
6565
self.is_acked = False
6666

taskiq/cli/scheduler/run.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,8 @@ async def get_schedules(source: ScheduleSource) -> list[ScheduledTask]:
4747
"""
4848
try:
4949
return await source.get_schedules()
50-
except Exception as exc:
51-
logger.error(
52-
"Cannot update schedules with source: %s\n%s{}",
53-
source,
54-
exc,
55-
exc_info=True,
56-
)
50+
except Exception:
51+
logger.exception("Cannot update schedules with source: %s", source)
5752
return []
5853

5954

taskiq/cli/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ def add_cwd_in_path() -> Generator[None, None, None]:
2525
if str(cwd) in sys.path:
2626
yield
2727
else:
28-
logger.debug(f"Inserting {cwd} in sys.path")
28+
logger.debug("Inserting %s in sys.path", cwd)
2929
sys.path.insert(0, str(cwd))
3030
try:
3131
yield
3232
finally:
3333
try:
3434
sys.path.remove(str(cwd))
3535
except ValueError:
36-
logger.warning(f"Cannot remove '{cwd}' from sys.path")
36+
logger.warning("Cannot remove '%s' from sys.path", cwd)
3737

3838

3939
def import_object(object_spec: str, app_dir: str | None = None) -> Any:
@@ -63,11 +63,11 @@ def import_from_modules(modules: list[str]) -> None:
6363
"""
6464
for module in modules:
6565
try:
66-
logger.info(f"Importing tasks from module {module}")
66+
logger.info("Importing tasks from module %s", module)
6767
with add_cwd_in_path():
6868
import_module(module)
6969
except ImportError as err:
70-
logger.warning(f"Cannot import {module}. Cause:")
70+
logger.warning("Cannot import %s. Cause:", module)
7171
logger.exception(err)
7272

7373

taskiq/cli/watcher.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ def dispatch(self, event: FileSystemEvent) -> None:
5656
return
5757
except Exception as exc:
5858
logger.info(
59-
f"Cannot check path `{event.src_path!r}` in gitignore. Cause: {exc}",
59+
"Cannot check path `%r` in gitignore. Cause: %s",
60+
event.src_path,
61+
exc,
6062
)
6163
return
6264

63-
logger.debug(f"File changed. Event: {event}")
65+
logger.debug("File changed. Event: %s", event)
6466
self.callback(**self.callback_kwargs)

taskiq/cli/worker/process_manager.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def handle(
7777
try:
7878
worker.terminate()
7979
except ValueError:
80-
logger.debug(f"Process {worker.name} is already terminated.")
80+
logger.debug("Process %s is already terminated.", worker.name)
8181
# Waiting worker shutdown.
8282
worker.join()
8383
event: EventType = Event()
@@ -88,7 +88,11 @@ def handle(
8888
daemon=False,
8989
)
9090
new_process.start()
91-
logger.info(f"Process {new_process.name} restarted with pid {new_process.pid}")
91+
logger.info(
92+
"Process %s restarted with pid %s",
93+
new_process.name,
94+
new_process.pid,
95+
)
9296
workers[self.worker_num] = new_process
9397
_wait_for_worker_startup(new_process, event)
9498

@@ -139,7 +143,7 @@ def _signal_handler(signum: int, _frame: Any) -> None:
139143
if current_process().name.startswith("worker"):
140144
raise KeyboardInterrupt
141145

142-
logger.debug(f"Got signal {signum}.")
146+
logger.debug("Got signal %s.", signum)
143147
action_queue.put(action_to_send)
144148
logger.info("Workers are scheduled for shutdown.")
145149

@@ -167,7 +171,7 @@ def __init__(
167171
if args.reload and observer is not None:
168172
watch_paths = args.reload_dirs if args.reload_dirs else ["."]
169173
for path_to_watch in watch_paths:
170-
logger.debug(f"Watching directory: {path_to_watch}")
174+
logger.debug("Watching directory: %s", path_to_watch)
171175
observer.schedule(
172176
FileWatcher(
173177
callback=schedule_workers_reload,
@@ -267,7 +271,7 @@ def start(self) -> int | None: # noqa: C901
267271
# We bulk_process all pending events.
268272
while not self.action_queue.empty():
269273
action = self.action_queue.get()
270-
logging.debug(f"Got event: {action}")
274+
logging.debug("Got event: %s", action)
271275
if isinstance(action, ReloadAllAction):
272276
action.handle(
273277
workers_num=len(self.workers),
@@ -295,7 +299,7 @@ def start(self) -> int | None: # noqa: C901
295299

296300
for worker_num, worker in enumerate(self.workers):
297301
if not worker.is_alive():
298-
logger.info(f"{worker.name} is dead. Scheduling reload.")
302+
logger.info("%s is dead. Scheduling reload.", worker.name)
299303
self.action_queue.put(
300304
ReloadOneAction(
301305
worker_num=worker_num,

taskiq/cli/worker/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def interrupt_handler(signum: int, _frame: Any) -> None:
103103
:param _frame: current execution frame.
104104
:raises KeyboardInterrupt: if termination hasn't begun.
105105
"""
106-
logger.debug(f"Got signal {signum}.")
106+
logger.debug("Got signal %s.", signum)
107107
nonlocal shutdown_event
108108
nonlocal hardkill_counter
109109
# Soft kill is a signal to start shutdown.

0 commit comments

Comments
 (0)