Skip to content

Commit fcf9a78

Browse files
author
arya dradjica
committed
Use lazy logging instead of f-strings
See: <#5337 (comment)>
1 parent 7dc6a97 commit fcf9a78

9 files changed

+29
-23
lines changed

beets/importer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,7 @@ def resolve_duplicates(session, task):
15821582
if task.choice_flag in (action.ASIS, action.APPLY, action.RETAG):
15831583
found_duplicates = task.find_duplicates(session.lib)
15841584
if found_duplicates:
1585-
log.debug(f"found duplicates: {[o.id for o in found_duplicates]}")
1585+
log.debug("found duplicates: {0}", [o.id for o in found_duplicates])
15861586

15871587
# Get the default action to follow from config.
15881588
duplicate_action = config["import"]["duplicate_action"].as_choice(

beetsplug/bpd/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1111,8 +1111,8 @@ def __init__(self, library, host, port, password, ctrl_port, log):
11111111
self.lib = library
11121112
self.player = gstplayer.GstPlayer(self.play_finished)
11131113
self.cmd_update(None)
1114-
log.info(f"Server ready and listening on {host}:{port}")
1115-
log.debug(f"Listening for control signals on {host}:{ctrl_port}")
1114+
log.info("Server ready and listening on {}:{}", host, port)
1115+
log.debug("Listening for control signals on {}:{}", host, ctrl_port)
11161116

11171117
def run(self):
11181118
self.player.run()

beetsplug/embedart.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def embed_func(lib, opts, args):
149149
with open(tempimg, "wb") as f:
150150
f.write(response.content)
151151
except Exception as e:
152-
self._log.error(f"Unable to save image: {e}")
152+
self._log.error("Unable to save image: {}", e)
153153
return
154154
items = lib.items(decargs(args))
155155
# Confirm with user.

beetsplug/fetchart.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -455,14 +455,14 @@ def get_image_urls(url, preferred_width=None):
455455
try:
456456
response = self.request(url)
457457
except requests.RequestException:
458-
self._log.debug(f"{self.NAME}: error receiving response")
458+
self._log.debug("{}: error receiving response", self.NAME)
459459
return
460460

461461
try:
462462
data = response.json()
463463
except ValueError:
464464
self._log.debug(
465-
f"{self.NAME}: error loading response: {response.text}"
465+
"{}: error loading response: {}", self.NAME, response.text
466466
)
467467
return
468468

@@ -596,7 +596,7 @@ def get(self, album, plugin, paths):
596596
try:
597597
data = response.json()
598598
except ValueError:
599-
self._log.debug(f"google: error loading response: {response.text}")
599+
self._log.debug("google: error loading response: {}", response.text)
600600
return
601601

602602
if "error" in data:
@@ -1064,7 +1064,7 @@ def get(self, album, plugin, paths):
10641064
url=images[size], size=self.SIZES[size]
10651065
)
10661066
except ValueError:
1067-
self._log.debug(f"lastfm: error loading response: {response.text}")
1067+
self._log.debug("lastfm: error loading response: {}", response.text)
10681068
return
10691069

10701070

@@ -1123,14 +1123,14 @@ def get(self, album, plugin, paths):
11231123
image_url = album.cover_art_url
11241124
else:
11251125
image_url = album.items().get().cover_art_url
1126-
self._log.debug(f"Cover art URL {image_url} found for {album}")
1126+
self._log.debug("Cover art URL {} found for {}", image_url, album)
11271127
except (AttributeError, TypeError):
1128-
self._log.debug(f"Cover art URL not found for {album}")
1128+
self._log.debug("Cover art URL not found for {}", album)
11291129
return
11301130
if image_url:
11311131
yield self._candidate(url=image_url, match=Candidate.MATCH_EXACT)
11321132
else:
1133-
self._log.debug(f"Cover art URL not found for {album}")
1133+
self._log.debug("Cover art URL not found for {}", album)
11341134
return
11351135

11361136

beetsplug/fromfilename.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def apply_matches(d, log):
112112
for item in d:
113113
if not item.artist:
114114
item.artist = artist
115-
log.info(f"Artist replaced with: {item.artist}")
115+
log.info("Artist replaced with: {}", item.artist)
116116

117117
# No artist field: remaining field is the title.
118118
else:
@@ -122,11 +122,11 @@ def apply_matches(d, log):
122122
for item in d:
123123
if bad_title(item.title):
124124
item.title = str(d[item][title_field])
125-
log.info(f"Title replaced with: {item.title}")
125+
log.info("Title replaced with: {}", item.title)
126126

127127
if "track" in d[item] and item.track == 0:
128128
item.track = int(d[item]["track"])
129-
log.info(f"Track replaced with: {item.track}")
129+
log.info("Track replaced with: {}", item.track)
130130

131131

132132
# Plugin structure and hook into import process.

beetsplug/metasync/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ def func(self, lib, opts, args):
118118
try:
119119
cls = META_SOURCES[player]
120120
except KeyError:
121-
self._log.error(f"Unknown metadata source '{player}'")
121+
self._log.error("Unknown metadata source '{}'", player)
122122

123123
try:
124124
meta_source_instances[player] = cls(self.config, self._log)
125125
except (ImportError, ConfigValueError) as e:
126126
self._log.error(
127-
f"Failed to instantiate metadata source {player!r}: {e}"
127+
"Failed to instantiate metadata source {!r}: {}", player, e
128128
)
129129

130130
# Avoid needlessly iterating over items

beetsplug/playlist.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,10 @@ def update_playlist(self, filename, base_dir):
192192

193193
if changes or deletions:
194194
self._log.info(
195-
f"Updated playlist {filename} "
196-
f"({changes} changes, {deletions} deletions)"
195+
"Updated playlist {} ({} changes, {} deletions)",
196+
filename,
197+
changes,
198+
deletions,
197199
)
198200
beets.util.copy(new_playlist, filename, replace=True)
199201
beets.util.remove(new_playlist)

beetsplug/replaygain.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,10 @@ def _analyse_item(
509509
if self._parse_float(b"M: " + line[1]) >= gating_threshold:
510510
n_blocks += 1
511511
self._log.debug(
512-
f"{item}: {n_blocks} blocks over {gating_threshold} LUFS"
512+
"{}: {} blocks over {} LUFS", item, n_blocks, gating_threshold
513513
)
514514

515-
self._log.debug(f"{item}: gain {gain} LU, peak {peak}")
515+
self._log.debug("{}: gain {} LU, peak {}", item, gain, peak)
516516

517517
return Gain(gain, peak), n_blocks
518518

@@ -1527,14 +1527,18 @@ def command_func(
15271527
if opts.album:
15281528
albums = lib.albums(ui.decargs(args))
15291529
self._log.info(
1530-
f"Analyzing {len(albums)} albums ~ {self.backend_name} backend..."
1530+
"Analyzing {} albums ~ {} backend...",
1531+
len(albums),
1532+
self.backend_name,
15311533
)
15321534
for album in albums:
15331535
self.handle_album(album, write, force)
15341536
else:
15351537
items = lib.items(ui.decargs(args))
15361538
self._log.info(
1537-
f"Analyzing {len(items)} tracks ~ {self.backend_name} backend..."
1539+
"Analyzing {} tracks ~ {} backend...",
1540+
len(items),
1541+
self.backend_name,
15381542
)
15391543
for item in items:
15401544
self.handle_track(item, write, force)

beetsplug/spotify.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ def _output_match_results(self, results):
624624
spotify_ids = [track_data["id"] for track_data in results]
625625
if self.config["mode"].get() == "open":
626626
self._log.info(
627-
f"Attempting to open {self.data_source} with playlist"
627+
"Attempting to open {} with playlist", self.data_source
628628
)
629629
spotify_url = "spotify:trackset:Playlist:" + ",".join(
630630
spotify_ids

0 commit comments

Comments
 (0)