Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use 'repr' and 'str' in place of '!r' and '!s'
See: <beetbox#5337 (comment)> diff --git c/beets/autotag/mb.py i/beets/autotag/mb.py index e16643d7..f152b567 100644 --- c/beets/autotag/mb.py +++ i/beets/autotag/mb.py @@ -66,7 +66,9 @@ class MusicBrainzAPIError(util.HumanReadableException): super().__init__(reason, verb, tb) def get_message(self): - return f"{self._reasonstr()} in {self.verb} with query {self.query!r}" + return ( + f"{self._reasonstr()} in {self.verb} with query {repr(self.query)}" + ) log = logging.getLogger("beets") diff --git c/beets/dbcore/db.py i/beets/dbcore/db.py index 55ba6f11..5aa75aa5 100755 --- c/beets/dbcore/db.py +++ i/beets/dbcore/db.py @@ -397,7 +397,7 @@ class Model(ABC): def __repr__(self) -> str: name = type(self).__name__ - fields = ", ".join(f"{k}={v!r}" for k, v in dict(self).items()) + fields = ", ".join(f"{k}={repr(v)}" for k, v in dict(self).items()) return f"{name}({fields})" def clear_dirty(self): @@ -558,12 +558,12 @@ class Model(ABC): def __getattr__(self, key): if key.startswith("_"): - raise AttributeError(f"model has no attribute {key!r}") + raise AttributeError(f"model has no attribute {repr(key)}") else: try: return self[key] except KeyError: - raise AttributeError(f"no such field {key!r}") + raise AttributeError(f"no such field {repr(key)}") def __setattr__(self, key, value): if key.startswith("_"): diff --git c/beets/dbcore/query.py i/beets/dbcore/query.py index 357b5685..6e94ddd5 100644 --- c/beets/dbcore/query.py +++ i/beets/dbcore/query.py @@ -171,7 +171,7 @@ class FieldQuery(Query, Generic[P]): def __repr__(self) -> str: return ( - f"{self.__class__.__name__}({self.field_name!r}, {self.pattern!r}, " + f"{self.__class__.__name__}({repr(self.field_name)}, {repr(self.pattern)}, " f"fast={self.fast})" ) @@ -210,7 +210,9 @@ class NoneQuery(FieldQuery[None]): return obj.get(self.field_name) is None def __repr__(self) -> str: - return f"{self.__class__.__name__}({self.field_name!r}, {self.fast})" + return ( + f"{self.__class__.__name__}({repr(self.field_name)}, {self.fast})" + ) class StringFieldQuery(FieldQuery[P]): @@ -503,7 +505,7 @@ class CollectionQuery(Query): return clause, subvals def __repr__(self) -> str: - return f"{self.__class__.__name__}({self.subqueries!r})" + return f"{self.__class__.__name__}({repr(self.subqueries)})" def __eq__(self, other) -> bool: return super().__eq__(other) and self.subqueries == other.subqueries @@ -548,7 +550,7 @@ class AnyFieldQuery(CollectionQuery): def __repr__(self) -> str: return ( - f"{self.__class__.__name__}({self.pattern!r}, {self.fields!r}, " + f"{self.__class__.__name__}({repr(self.pattern)}, {repr(self.fields)}, " f"{self.query_class.__name__})" ) @@ -619,7 +621,7 @@ class NotQuery(Query): return not self.subquery.match(obj) def __repr__(self) -> str: - return f"{self.__class__.__name__}({self.subquery!r})" + return f"{self.__class__.__name__}({repr(self.subquery)})" def __eq__(self, other) -> bool: return super().__eq__(other) and self.subquery == other.subquery @@ -975,7 +977,7 @@ class MultipleSort(Sort): return items def __repr__(self): - return f"{self.__class__.__name__}({self.sorts!r})" + return f"{self.__class__.__name__}({repr(self.sorts)})" def __hash__(self): return hash(tuple(self.sorts)) @@ -1015,7 +1017,7 @@ class FieldSort(Sort): def __repr__(self) -> str: return ( f"{self.__class__.__name__}" - f"({self.field!r}, ascending={self.ascending!r})" + f"({repr(self.field)}, ascending={repr(self.ascending)})" ) def __hash__(self) -> int: diff --git c/beets/library.py i/beets/library.py index 77d24ecd..a9adc13d 100644 --- c/beets/library.py +++ i/beets/library.py @@ -156,7 +156,7 @@ class PathQuery(dbcore.FieldQuery[bytes]): def __repr__(self) -> str: return ( - f"{self.__class__.__name__}({self.field!r}, {self.pattern!r}, " + f"{self.__class__.__name__}({repr(self.field)}, {repr(self.pattern)}, " f"fast={self.fast}, case_sensitive={self.case_sensitive})" ) @@ -735,7 +735,7 @@ class Item(LibModel): # can even deadlock due to the database lock. name = type(self).__name__ keys = self.keys(with_album=False) - fields = (f"{k}={self[k]!r}" for k in keys) + fields = (f"{k}={repr(self[k])}" for k in keys) return f"{name}({', '.join(fields)})" def keys(self, computed=False, with_album=True): @@ -1578,7 +1578,7 @@ def parse_query_string(s, model_cls): The string is split into components using shell-like syntax. """ - message = f"Query is not unicode: {s!r}" + message = f"Query is not unicode: {repr(s)}" assert isinstance(s, str), message try: parts = shlex.split(s) diff --git c/beets/test/_common.py i/beets/test/_common.py index c12838e2..0bc1baf8 100644 --- c/beets/test/_common.py +++ i/beets/test/_common.py @@ -152,7 +152,7 @@ class Assertions: """A mixin with additional unit test assertions.""" def assertExists(self, path): # noqa - assert os.path.exists(syspath(path)), f"file does not exist: {path!r}" + assert os.path.exists(syspath(path)), f"file does not exist: {repr(path)}" def assertNotExists(self, path): # noqa assert not os.path.exists(syspath(path)), f"file exists: {repr(path)}" @@ -186,7 +186,7 @@ class InputException(Exception): def __str__(self): msg = "Attempt to read with no input provided." if self.output is not None: - msg += f" Output: {self.output!r}" + msg += f" Output: {repr(self.output)}" return msg diff --git c/beets/ui/commands.py i/beets/ui/commands.py index 3042ca77..a717c94c 100755 --- c/beets/ui/commands.py +++ i/beets/ui/commands.py @@ -213,7 +213,7 @@ def get_singleton_disambig_fields(info: hooks.TrackInfo) -> Sequence[str]: out = [] chosen_fields = config["match"]["singleton_disambig_fields"].as_str_seq() calculated_values = { - "index": f"Index {info.index!s}", + "index": f"Index {str(info.index)}", "track_alt": f"Track {info.track_alt}", "album": ( f"[{info.album}]" diff --git c/beets/util/__init__.py i/beets/util/__init__.py index aa94b6d2..a0f13fa1 100644 --- c/beets/util/__init__.py +++ i/beets/util/__init__.py @@ -104,7 +104,7 @@ class HumanReadableException(Exception): elif hasattr(self.reason, "strerror"): # i.e., EnvironmentError return self.reason.strerror else: - return f'"{self.reason!s}"' + return f'"{str(self.reason)}"' def get_message(self): """Create the human-readable description of the error, sans diff --git c/beets/util/functemplate.py i/beets/util/functemplate.py index 35f60b7d..f149d370 100644 --- c/beets/util/functemplate.py +++ i/beets/util/functemplate.py @@ -166,7 +166,7 @@ class Call: self.original = original def __repr__(self): - return f"Call({self.ident!r}, {self.args!r}, {self.original!r})" + return f"Call({repr(self.ident)}, {repr(self.args)}, {repr(self.original)})" def evaluate(self, env): """Evaluate the function call in the environment, returning a diff --git c/beetsplug/bpd/__init__.py i/beetsplug/bpd/__init__.py index d6c75380..3336702c 100644 --- c/beetsplug/bpd/__init__.py +++ i/beetsplug/bpd/__init__.py @@ -1142,7 +1142,7 @@ class Server(BaseServer): pass for tagtype, field in self.tagtype_map.items(): - info_lines.append(f"{tagtype}: {getattr(item, field)!s}") + info_lines.append(f"{tagtype}: {str(getattr(item, field))}") return info_lines @@ -1301,7 +1301,7 @@ class Server(BaseServer): yield ( f"bitrate: {item.bitrate / 1000}", - f"audio: {item.samplerate!s}:{item.bitdepth!s}:{item.channels!s}", + f"audio: {str(item.samplerate)}:{str(item.bitdepth)}:{str(item.channels)}", ) (pos, total) = self.player.time() diff --git c/beetsplug/edit.py i/beetsplug/edit.py index 61f2020a..20430255 100644 --- c/beetsplug/edit.py +++ i/beetsplug/edit.py @@ -47,7 +47,9 @@ def edit(filename, log): try: subprocess.call(cmd) except OSError as exc: - raise ui.UserError(f"could not run editor command {cmd[0]!r}: {exc}") + raise ui.UserError( + f"could not run editor command {repr(cmd[0])}: {exc}" + ) def dump(arg): diff --git c/beetsplug/replaygain.py i/beetsplug/replaygain.py index 78cce1e6..1c8aaaa9 100644 --- c/beetsplug/replaygain.py +++ i/beetsplug/replaygain.py @@ -534,7 +534,7 @@ class FfmpegBackend(Backend): if output[i].startswith(search): return i raise ReplayGainError( - f"ffmpeg output: missing {search!r} after line {start_line}" + f"ffmpeg output: missing {repr(search)} after line {start_line}" ) def _parse_float(self, line: bytes) -> float: @@ -547,7 +547,7 @@ class FfmpegBackend(Backend): parts = line.split(b":", 1) if len(parts) < 2: raise ReplayGainError( - f"ffmpeg output: expected key value pair, found {line!r}" + f"ffmpeg output: expected key value pair, found {repr(line)}" ) value = parts[1].lstrip() # strip unit @@ -557,7 +557,7 @@ class FfmpegBackend(Backend): return float(value) except ValueError: raise ReplayGainError( - f"ffmpeg output: expected float value, found {value!r}" + f"ffmpeg output: expected float value, found {repr(value)}" ) @@ -886,7 +886,7 @@ class GStreamerBackend(Backend): f = self._src.get_property("location") # A GStreamer error, either an unsupported format or a bug. self._error = ReplayGainError( - f"Error {err!r} - {debug!r} on file {f!r}" + f"Error {repr(err)} - {repr(debug)} on file {repr(f)}" ) def _on_tag(self, bus, message): diff --git c/beetsplug/thumbnails.py i/beetsplug/thumbnails.py index acca413d..0cde56c7 100644 --- c/beetsplug/thumbnails.py +++ i/beetsplug/thumbnails.py @@ -292,4 +292,6 @@ class GioURI(URIGetter): try: return uri.decode(util._fsencoding()) except UnicodeDecodeError: - raise RuntimeError(f"Could not decode filename from GIO: {uri!r}") + raise RuntimeError( + f"Could not decode filename from GIO: {repr(uri)}" + ) diff --git c/test/plugins/test_lyrics.py i/test/plugins/test_lyrics.py index 7cb081fc..484d4889 100644 --- c/test/plugins/test_lyrics.py +++ i/test/plugins/test_lyrics.py @@ -223,9 +223,9 @@ class LyricsAssertions: if not keywords <= words: details = ( - f"{keywords!r} is not a subset of {words!r}." - f" Words only in expected set {keywords - words!r}," - f" Words only in result set {words - keywords!r}." + f"{repr(keywords)} is not a subset of {repr(words)}." + f" Words only in expected set {repr(keywords - words)}," + f" Words only in result set {repr(words - keywords)}." ) self.fail(f"{details} : {msg}") diff --git c/test/plugins/test_player.py i/test/plugins/test_player.py index bf466e1b..e23b6396 100644 --- c/test/plugins/test_player.py +++ i/test/plugins/test_player.py @@ -132,7 +132,7 @@ class MPCResponse: cmd, rest = rest[2:].split("}") return False, (int(code), int(pos), cmd, rest[1:]) else: - raise RuntimeError(f"Unexpected status: {status!r}") + raise RuntimeError(f"Unexpected status: {repr(status)}") def _parse_body(self, body): """Messages are generally in the format "header: content". @@ -145,7 +145,7 @@ class MPCResponse: if not line: continue if ":" not in line: - raise RuntimeError(f"Unexpected line: {line!r}") + raise RuntimeError(f"Unexpected line: {repr(line)}") header, content = line.split(":", 1) content = content.lstrip() if header in repeated_headers: @@ -191,7 +191,7 @@ class MPCClient: responses.append(MPCResponse(response)) response = b"" elif not line: - raise RuntimeError(f"Unexpected response: {line!r}") + raise RuntimeError(f"Unexpected response: {repr(line)}") def serialise_command(self, command, *args): cmd = [command.encode("utf-8")] diff --git c/test/plugins/test_thumbnails.py i/test/plugins/test_thumbnails.py index 07775995..1931061b 100644 --- c/test/plugins/test_thumbnails.py +++ i/test/plugins/test_thumbnails.py @@ -71,7 +71,7 @@ class ThumbnailsTest(BeetsTestCase): return False if path == syspath(LARGE_DIR): return True - raise ValueError(f"unexpected path {path!r}") + raise ValueError(f"unexpected path {repr(path)}") mock_os.path.exists = exists plugin = ThumbnailsPlugin()
- Loading branch information