From d43b6c75b3b640ad7e9ec654db855d82c79e1fb4 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:20:36 +0200 Subject: [PATCH] Use lazy % formatting in logging functions (#2366) * Use lazy % formatting in logging functions * f-string should be more efficient * Space before unit symbol From "SI Unit rules and style conventions": https://physics.nist.gov/cuu/Units/checklist.html There is a space between the numerical value and unit symbol, even when the value is used in an adjectival sense, except in the case of superscript units for plane angle. * Enforce ruff/flake8-logging-format rules (G) --------- Co-authored-by: Joe Hamman --- pyproject.toml | 1 + src/zarr/core/sync.py | 2 +- src/zarr/storage/logging.py | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 593be36b75..059fa8fdb7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -211,6 +211,7 @@ extend-select = [ "B", # flake8-bugbear "C4", # flake8-comprehensions "FLY", # flynt + "G", # flake8-logging-format "I", # isort "ISC", # flake8-implicit-str-concat "PGH", # pygrep-hooks diff --git a/src/zarr/core/sync.py b/src/zarr/core/sync.py index 20f04f543b..8c5bc9c397 100644 --- a/src/zarr/core/sync.py +++ b/src/zarr/core/sync.py @@ -133,7 +133,7 @@ def sync( finished, unfinished = wait([future], return_when=asyncio.ALL_COMPLETED, timeout=timeout) if len(unfinished) > 0: - raise TimeoutError(f"Coroutine {coro} failed to finish in within {timeout}s") + raise TimeoutError(f"Coroutine {coro} failed to finish in within {timeout} s") assert len(finished) == 1 return_result = next(iter(finished)).result() diff --git a/src/zarr/storage/logging.py b/src/zarr/storage/logging.py index 59a796dc18..a29661729f 100644 --- a/src/zarr/storage/logging.py +++ b/src/zarr/storage/logging.py @@ -83,15 +83,15 @@ def log(self, hint: Any = "") -> Generator[None, None, None]: method = inspect.stack()[2].function op = f"{type(self._store).__name__}.{method}" if hint: - op += f"({hint})" - self.logger.info(f"Calling {op}") + op = f"{op}({hint})" + self.logger.info("Calling %s", op) start_time = time.time() try: self.counter[method] += 1 yield finally: end_time = time.time() - self.logger.info(f"Finished {op} [{end_time - start_time:.2f}s]") + self.logger.info("Finished %s [%.2f s]", op, end_time - start_time) @property def supports_writes(self) -> bool: