Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change occurrences of % and format() to f-strings #1423

Merged
merged 3 commits into from Feb 16, 2024

Conversation

DimitriPapadopoulos
Copy link
Contributor

@DimitriPapadopoulos DimitriPapadopoulos commented May 31, 2023

The rationale is that f-strings are faster.

TODO:

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/tutorial.rst
  • Changes documented in docs/release.rst
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

@github-actions github-actions bot added the needs release notes Automatically applied to PRs which haven't added release notes label May 31, 2023
@github-actions github-actions bot removed the needs release notes Automatically applied to PRs which haven't added release notes label May 31, 2023
@codecov
Copy link

codecov bot commented May 31, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (720bea6) 99.99% compared to head (46989fd) 99.99%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1423   +/-   ##
=======================================
  Coverage   99.99%   99.99%           
=======================================
  Files          38       38           
  Lines       14574    14574           
=======================================
  Hits        14573    14573           
  Misses          1        1           
Files Coverage Δ
zarr/_storage/absstore.py 100.00% <100.00%> (ø)
zarr/_storage/store.py 100.00% <100.00%> (ø)
zarr/_storage/v3.py 100.00% <ø> (ø)
zarr/convenience.py 100.00% <100.00%> (ø)
zarr/core.py 100.00% <100.00%> (ø)
zarr/creation.py 100.00% <100.00%> (ø)
zarr/errors.py 100.00% <100.00%> (ø)
zarr/hierarchy.py 100.00% <100.00%> (ø)
zarr/indexing.py 100.00% <100.00%> (ø)
zarr/meta.py 100.00% <100.00%> (ø)
... and 6 more

@d-v-b
Copy link
Contributor

d-v-b commented Jul 19, 2023

I will fix these conflicts, and then I think this should be good to go in.

@d-v-b
Copy link
Contributor

d-v-b commented Jul 19, 2023

@rabernat any objection to getting this in to the release?

@@ -497,7 +497,7 @@ def __init__(self, log):
self.log_file = log
else:
raise TypeError(
"log must be a callable function, file path or " "file-like object, found %r" % log
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This string was cut in half, looks like a left-over from #1459.

zarr/convenience.py Outdated Show resolved Hide resolved
@@ -949,7 +943,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
if do_copy:

# log a message about what we're going to do
log("copy {} {} {}".format(source.name, source.shape, source.dtype))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps log("{}".format(arg)) should actually be changed to log("%s", arg), so that string formatting interpolation is not executed if logging is not enabled.

See also:

@DimitriPapadopoulos DimitriPapadopoulos marked this pull request as ready for review December 7, 2023 22:29
@joshmoore
Copy link
Member

Conflicts fixed. @DimitriPapadopoulos: please note it looks like 46989fd#diff-35a6b5d683684d4a73baf73ec18e5a438a738b98e3138b494834bca5add5ba4bR1399 was missing an f?

@DimitriPapadopoulos
Copy link
Contributor Author

Conflicts fixed. @DimitriPapadopoulos: please note it looks like 46989fd#diff-35a6b5d683684d4a73baf73ec18e5a438a738b98e3138b494834bca5add5ba4bR1399 was missing an f?

Indeed, sorry about that. Because pyupgrade cannot be restricted to a specific rule and misses some cases, it wasn't easy to automate such changes. I guess ruff is a better alternative because you can --select specific rules and --fix issues.

@joshmoore joshmoore merged commit 003ff33 into zarr-developers:main Feb 16, 2024
17 checks passed
@DimitriPapadopoulos DimitriPapadopoulos deleted the f-strings branch February 16, 2024 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants