Skip to content

Commit

Permalink
Use lazy % formatting in logging functions (zarr-developers#2366)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
DimitriPapadopoulos and jhamman authored Oct 15, 2024

Verified

This commit was signed with the committer’s verified signature.
kyteinsky Anupam Kumar
1 parent fe752a2 commit d43b6c7
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/zarr/core/sync.py
Original file line number Diff line number Diff line change
@@ -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()

6 changes: 3 additions & 3 deletions src/zarr/storage/logging.py
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit d43b6c7

Please sign in to comment.