From c6a76e221f146d93ea67fb7cd664ea5e971ef415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Wed, 19 Jun 2024 16:08:32 +0000 Subject: [PATCH] Fix ruff issues --- breezy/__main__.py | 4 +- breezy/builtins.py | 5 +- breezy/bzr/branch.py | 4 +- breezy/bzr/bundle/bundle_data.py | 18 +++---- breezy/bzr/bundle/serializer/v08.py | 4 +- breezy/bzr/bzrdir.py | 2 +- breezy/bzr/dirstate.py | 4 +- breezy/bzr/groupcompress.py | 2 +- breezy/bzr/inventory.py | 2 +- breezy/bzr/tests/matchers.py | 4 +- breezy/bzr/tests/per_bzrdir/test_bzrdir.py | 4 +- .../per_repository_vf/test_fileid_involved.py | 2 +- .../per_repository_vf/test_refresh_data.py | 3 +- breezy/bzr/tests/test_bundle.py | 4 +- breezy/bzr/transform.py | 3 +- breezy/bzr/weave.py | 4 +- breezy/bzr/workingtree.py | 2 +- breezy/bzr/xml8.py | 2 +- breezy/commands.py | 3 +- breezy/config.py | 6 +-- breezy/controldir.py | 2 +- breezy/crash.py | 5 +- breezy/directory_service.py | 4 +- breezy/git/transform.py | 3 +- breezy/info.py | 6 +-- breezy/log.py | 4 +- breezy/lsprof.py | 3 +- breezy/mail_client.py | 22 ++++----- breezy/merge.py | 9 ++-- breezy/mergetools.py | 2 +- breezy/msgeditor.py | 4 +- breezy/plugins/bash_completion/bashcomp.py | 4 +- .../plugins/fastimport/bzr_commit_handler.py | 2 +- breezy/plugins/weave_fmt/test_bzrdir.py | 2 +- breezy/plugins/webdav/tests/dav_server.py | 2 +- breezy/plugins/zsh_completion/zshcomp.py | 4 +- breezy/push.py | 4 +- breezy/symbol_versioning.py | 4 +- breezy/tests/blackbox/test_branch.py | 4 +- breezy/tests/blackbox/test_info.py | 7 ++- breezy/tests/blackbox/test_missing.py | 6 +-- breezy/tests/blackbox/test_push.py | 20 ++++---- breezy/tests/blackbox/test_status.py | 2 +- breezy/tests/blackbox/test_update.py | 47 ++++++++----------- breezy/tests/http_server.py | 3 +- breezy/tests/per_branch/test_tags.py | 2 +- .../tests/per_controldir/test_controldir.py | 6 +-- .../test_interrepository.py | 2 +- breezy/tests/per_repository/test_fetch.py | 2 +- breezy/tests/per_transport.py | 11 ++--- .../per_workingtree/test_eol_conversion.py | 4 +- breezy/tests/per_workingtree/test_pull.py | 2 +- breezy/tests/per_workingtree/test_views.py | 4 +- .../tests/per_workingtree/test_workingtree.py | 2 +- breezy/tests/test_config.py | 5 +- breezy/tests/test_email_message.py | 9 ++-- breezy/tests/test_errors.py | 7 ++- breezy/tests/test_http.py | 16 +++---- breezy/tests/test_mail_client.py | 2 +- breezy/tests/test_mergetools.py | 2 +- breezy/tests/test_msgeditor.py | 4 +- breezy/tests/test_source.py | 11 ++--- breezy/tests/test_version.py | 2 +- breezy/transport/__init__.py | 4 +- breezy/transport/gio_transport.py | 14 +++--- breezy/transport/http/urllib.py | 4 +- breezy/tree.py | 6 +-- breezy/ui/__init__.py | 4 +- 68 files changed, 178 insertions(+), 204 deletions(-) diff --git a/breezy/__main__.py b/breezy/__main__.py index 1aa2642235..5678e1e8a2 100644 --- a/breezy/__main__.py +++ b/breezy/__main__.py @@ -35,11 +35,11 @@ locale.setlocale(locale.LC_ALL, "") except locale.Error as e: sys.stderr.write( - "brz: warning: %s\n" + "brz: warning: {}\n" " bzr could not set the application locale.\n" " Although this should be no problem for bzr itself, it might\n" " cause problems with some plugins. To investigate the issue,\n" - " look at the output of the locale(1p) tool.\n" % e + " look at the output of the locale(1p) tool.\n".format(e) ) # Use better default than ascii with posix filesystems that deal in bytes # natively even when the C locale or no locale at all is given. Note that diff --git a/breezy/builtins.py b/breezy/builtins.py index 83dd050e18..a3bde3f79d 100644 --- a/breezy/builtins.py +++ b/breezy/builtins.py @@ -1775,10 +1775,9 @@ def run(self, location=".", recursive=False): raise errors.CommandError("Can't scan this type of location.") for b in controldir.ControlDir.find_branches(t): self.outf.write( - "%s\n" - % urlutils.unescape_for_display( + "{}\n".format(urlutils.unescape_for_display( urlutils.relative_url(t.base, b.base), self.outf.encoding - ).rstrip("/") + ).rstrip("/")) ) else: dir = controldir.ControlDir.open_containing(location)[0] diff --git a/breezy/bzr/branch.py b/breezy/bzr/branch.py index eac1df6356..df7eb02a79 100644 --- a/breezy/bzr/branch.py +++ b/breezy/bzr/branch.py @@ -645,8 +645,8 @@ def _open_hook(self, possible_transports=None): if url is None: hook_name = Branch.hooks.get_hook_name(hook) raise AssertionError( - "'transform_fallback_location' hook %s returned " - "None, not a URL." % hook_name + "'transform_fallback_location' hook {} returned " + "None, not a URL.".format(hook_name) ) self._activate_fallback_location( url, possible_transports=possible_transports diff --git a/breezy/bzr/bundle/bundle_data.py b/breezy/bzr/bundle/bundle_data.py index 1a58bb16af..38d234f283 100644 --- a/breezy/bzr/bundle/bundle_data.py +++ b/breezy/bzr/bundle/bundle_data.py @@ -297,7 +297,7 @@ def _validate_revision(self, tree, revision_id): if sha1 != rev_info.sha1: raise TestamentMismatch(rev.revision_id, rev_info.sha1, sha1) if rev.revision_id in rev_to_sha1: - raise BzrError("Revision {%s} given twice in the list" % (rev.revision_id)) + raise BzrError("Revision {{{}}} given twice in the list".format(rev.revision_id)) rev_to_sha1[rev.revision_id] = sha1 def _update_tree(self, bundle_tree, revision_id): @@ -349,7 +349,7 @@ def renamed(kind, extra, lines): info = extra.split(" // ") if len(info) < 2: raise BzrError( - "renamed action lines need both a from and to" ": %r" % extra + "renamed action lines need both a from and to" ": {!r}".format(extra) ) old_path = info[0] new_path = info[1][3:] if info[1].startswith("=> ") else info[1] @@ -366,7 +366,7 @@ def removed(kind, extra, lines): # TODO: in the future we might allow file ids to be # given for removed entries raise BzrError( - "removed action lines should only have the path" ": %r" % extra + "removed action lines should only have the path" ": {!r}".format(extra) ) path = info[0] bundle_tree.note_deletion(path) @@ -375,16 +375,16 @@ def added(kind, extra, lines): info = extra.split(" // ") if len(info) <= 1: raise BzrError( - "add action lines require the path and file id" ": %r" % extra + "add action lines require the path and file id" ": {!r}".format(extra) ) elif len(info) > 5: raise BzrError( - "add action lines have fewer than 5 entries." ": %r" % extra + "add action lines have fewer than 5 entries." ": {!r}".format(extra) ) path = info[0] if not info[1].startswith("file-id:"): raise BzrError( - "The file-id should follow the path for an add" ": %r" % extra + "The file-id should follow the path for an add" ": {!r}".format(extra) ) # This will be Unicode because of how the stream is read. Turn it # back into a utf8 file_id @@ -403,7 +403,7 @@ def modified(kind, extra, lines): info = extra.split(" // ") if len(info) < 1: raise BzrError( - "modified action lines have at least" "the path in them: %r" % extra + "modified action lines have at least" "the path in them: {!r}".format(extra) ) path = info[0] @@ -425,7 +425,7 @@ def modified(kind, extra, lines): second = action_line.find(" ", first + 1) if second == -1: raise BzrError( - "Bogus action line" " (missing second space): %r" % action_line + "Bogus action line" " (missing second space): {!r}".format(action_line) ) action = action_line[:first] kind = action_line[first + 1 : second] @@ -438,7 +438,7 @@ def modified(kind, extra, lines): if action not in valid_actions: raise BzrError( - "Bogus action line" " (unrecognized action): %r" % action_line + "Bogus action line" " (unrecognized action): {!r}".format(action_line) ) valid_actions[action](kind, extra, lines) diff --git a/breezy/bzr/bundle/serializer/v08.py b/breezy/bzr/bundle/serializer/v08.py index db6ab15750..69029eaa03 100644 --- a/breezy/bzr/bundle/serializer/v08.py +++ b/breezy/bzr/bundle/serializer/v08.py @@ -441,7 +441,7 @@ def _read_next_entry(self, line, indent=1): else: raise errors.MalformedHeader( "While looking for key: value pairs," - " did not find the colon %r" % (line) + " did not find the colon {!r}".format(line) ) key = key.replace(" ", "_") @@ -510,7 +510,7 @@ def _read_one_patch(self): raise errors.MalformedPatches( "The first line of all patches" ' should be a bzr meta line "==="' - ": %r" % line + ": {!r}".format(line) ) action = line[4:-1].decode("utf-8") elif line.startswith(b"... "): diff --git a/breezy/bzr/bzrdir.py b/breezy/bzr/bzrdir.py index bba0536a04..7551d67bf9 100644 --- a/breezy/bzr/bzrdir.py +++ b/breezy/bzr/bzrdir.py @@ -828,7 +828,7 @@ def create(cls, base, format=None, possible_transports=None) -> "BzrDir": if cls is not BzrDir: raise AssertionError( "BzrDir.create always creates the " - "default format, not one of %r" % cls + "default format, not one of {!r}".format(cls) ) if format is None: format = BzrDirFormat.get_default_format() diff --git a/breezy/bzr/dirstate.py b/breezy/bzr/dirstate.py index 670b9f9d45..e6a10a62aa 100644 --- a/breezy/bzr/dirstate.py +++ b/breezy/bzr/dirstate.py @@ -1410,7 +1410,7 @@ def _apply_removals(self, removals): self._raise_invalid( path, file_id, - "Attempt to remove path has wrong id - found %r." % entry[0][2], + "Attempt to remove path has wrong id - found {!r}.".format(entry[0][2]), ) self._make_absent(entry) # See if we have a malformed delta: deleting a directory must not @@ -3060,7 +3060,7 @@ def update_minimal( (b"%s/%s" % key[0:2]).decode("utf8"), key[2], "Attempt to add item at path already occupied by " - "id %r" % entry[0][2], + "id {!r}".format(entry[0][2]), ) low_index += 1 else: diff --git a/breezy/bzr/groupcompress.py b/breezy/bzr/groupcompress.py index 5a9dcc35de..3668938aa1 100644 --- a/breezy/bzr/groupcompress.py +++ b/breezy/bzr/groupcompress.py @@ -2096,7 +2096,7 @@ def add_records(self, records, random_id=False): details = f"{key} {value, node_refs} {passed}" if self._inconsistency_fatal: raise knit.KnitCorrupt( - self, "inconsistent details" " in add_records: %s" % details + self, "inconsistent details" " in add_records: {}".format(details) ) else: trace.warning( diff --git a/breezy/bzr/inventory.py b/breezy/bzr/inventory.py index 7b0aec2a97..bb6d47b30b 100644 --- a/breezy/bzr/inventory.py +++ b/breezy/bzr/inventory.py @@ -653,7 +653,7 @@ def create_by_apply_delta( raise errors.InconsistentDelta( old_path, file_id, - "Entry was at wrong other path %r." % self.id2path(file_id), + "Entry was at wrong other path {!r}.".format(self.id2path(file_id)), ) altered.add(file_id) id_to_entry_delta.append(StaticTuple(old_key, new_key, new_value)) diff --git a/breezy/bzr/tests/matchers.py b/breezy/bzr/tests/matchers.py index 735d953a4d..bbdfaae73f 100644 --- a/breezy/bzr/tests/matchers.py +++ b/breezy/bzr/tests/matchers.py @@ -44,12 +44,12 @@ def __init__(self, vfs_calls): self.vfs_calls = vfs_calls def describe(self): - return "no VFS calls expected, got: %s" % ",".join( + return "no VFS calls expected, got: {}".format(",".join( [ "{}({})".format(c.method, ", ".join([repr(a) for a in c.args])) for c in self.vfs_calls ] - ) + )) class ContainsNoVfsCalls(Matcher): diff --git a/breezy/bzr/tests/per_bzrdir/test_bzrdir.py b/breezy/bzr/tests/per_bzrdir/test_bzrdir.py index 975d44f0a4..76d8acdc4d 100644 --- a/breezy/bzr/tests/per_bzrdir/test_bzrdir.py +++ b/breezy/bzr/tests/per_bzrdir/test_bzrdir.py @@ -214,7 +214,7 @@ def skipIfNoWorkingTree(self, a_controldir): a_controldir.open_workingtree() except (errors.NotLocalUrl, errors.NoWorkingTree) as e: raise TestSkipped( - "bzrdir on transport %r has no working tree" % a_controldir.transport + "bzrdir on transport {!r} has no working tree".format(a_controldir.transport) ) from e def createWorkingTreeOrSkip(self, a_controldir): @@ -235,7 +235,7 @@ def createWorkingTreeOrSkip(self, a_controldir): ) except errors.NotLocalUrl as e: raise TestSkipped( - "cannot make working tree with transport %r" % a_controldir.transport + "cannot make working tree with transport {!r}".format(a_controldir.transport) ) from e def test_clone_bzrdir_repository_under_shared_force_new_repo(self): diff --git a/breezy/bzr/tests/per_repository_vf/test_fileid_involved.py b/breezy/bzr/tests/per_repository_vf/test_fileid_involved.py index 263f5d1006..f720174aa7 100644 --- a/breezy/bzr/tests/per_repository_vf/test_fileid_involved.py +++ b/breezy/bzr/tests/per_repository_vf/test_fileid_involved.py @@ -370,7 +370,7 @@ def test_utf8_file_ids_and_revision_ids(self): main_wt.commit("a", rev_id=revision_id) except errors.NonAsciiRevisionId as e: raise tests.TestSkipped( - "non-ascii revision ids not supported by %s" % self.repository_format + "non-ascii revision ids not supported by {}".format(self.repository_format) ) from e repo = main_wt.branch.repository diff --git a/breezy/bzr/tests/per_repository_vf/test_refresh_data.py b/breezy/bzr/tests/per_repository_vf/test_refresh_data.py index 2dbccb6a22..6c0957fe3d 100644 --- a/breezy/bzr/tests/per_repository_vf/test_refresh_data.py +++ b/breezy/bzr/tests/per_repository_vf/test_refresh_data.py @@ -50,8 +50,7 @@ def fetch_new_revision_into_concurrent_instance(self, repo, token): server_repo.lock_write(token) except errors.TokenLockingNotSupported: self.skipTest( - "Cannot concurrently insert into repo format %r" - % self.repository_format + "Cannot concurrently insert into repo format {!r}".format(self.repository_format) ) try: server_repo.fetch(source.branch.repository, revid) diff --git a/breezy/bzr/tests/test_bundle.py b/breezy/bzr/tests/test_bundle.py index 326e96063b..8b3671bf4b 100644 --- a/breezy/bzr/tests/test_bundle.py +++ b/breezy/bzr/tests/test_bundle.py @@ -529,14 +529,14 @@ def _valid_apply_bundle(self, base_rev_id, info, to_tree): for rev in info.real_revisions: self.assertTrue( not repository.has_revision(rev.revision_id), - "Revision {%s} present before applying bundle" % rev.revision_id, + "Revision {{{}}} present before applying bundle".format(rev.revision_id), ) merge_bundle(info, to_tree, True, merge.Merge3Merger, False, False) for rev in info.real_revisions: self.assertTrue( repository.has_revision(rev.revision_id), - "Missing revision {%s} after applying bundle" % rev.revision_id, + "Missing revision {{{}}} after applying bundle".format(rev.revision_id), ) self.assertTrue(to_tree.branch.repository.has_revision(info.target)) diff --git a/breezy/bzr/transform.py b/breezy/bzr/transform.py index 0074bf6bfa..717d28fbe4 100644 --- a/breezy/bzr/transform.py +++ b/breezy/bzr/transform.py @@ -849,8 +849,7 @@ def commit( parent_ids.extend(merge_parents) if self._tree.get_revision_id() != last_rev_id: raise ValueError( - "TreeTransform not based on branch basis: %s" - % self._tree.get_revision_id().decode("utf-8") + "TreeTransform not based on branch basis: {}".format(self._tree.get_revision_id().decode("utf-8")) ) from .. import commit diff --git a/breezy/bzr/weave.py b/breezy/bzr/weave.py index 4a8a386207..c86388163c 100755 --- a/breezy/bzr/weave.py +++ b/breezy/bzr/weave.py @@ -669,7 +669,7 @@ def _walk_internal(self, version_ids=None): if istack: raise WeaveFormatError( - "unclosed insertion blocks " "at end of weave: %s" % istack + "unclosed insertion blocks " "at end of weave: {}".format(istack) ) if dset: raise WeaveFormatError(f"unclosed deletion blocks at end of weave: {dset}") @@ -789,7 +789,7 @@ def _extract(self, versions): result.append((istack[-1], lineno, l)) if istack: raise WeaveFormatError( - "unclosed insertion blocks " "at end of weave: %s" % istack + "unclosed insertion blocks " "at end of weave: {}".format(istack) ) if dset: raise WeaveFormatError(f"unclosed deletion blocks at end of weave: {dset}") diff --git a/breezy/bzr/workingtree.py b/breezy/bzr/workingtree.py index db998e309c..442ceb0cb5 100644 --- a/breezy/bzr/workingtree.py +++ b/breezy/bzr/workingtree.py @@ -1563,7 +1563,7 @@ def _rollback_move(self, moved): "Rollback failed." " The working tree is in an inconsistent state." " Please consider doing a 'bzr revert'." - " Error message is: %s" % e, + " Error message is: {}".format(e), ) from e def _move_entry(self, entry): diff --git a/breezy/bzr/xml8.py b/breezy/bzr/xml8.py index 61a13580e8..047b235c64 100644 --- a/breezy/bzr/xml8.py +++ b/breezy/bzr/xml8.py @@ -196,7 +196,7 @@ def _find_text_key_references(self, line_iterator): raise AssertionError( "_find_text_key_references only " "supported for branches which store inventory as unnested xml" - ", not on %r" % self + ", not on {!r}".format(self) ) result = {} diff --git a/breezy/commands.py b/breezy/commands.py index 5c80db8919..88bf636474 100644 --- a/breezy/commands.py +++ b/breezy/commands.py @@ -134,8 +134,7 @@ def register(self, cmd, decorate=False): trace.warning(f"Two plugins defined the same command: {k!r}") trace.warning(f"Not loading the one in {sys.modules[cmd.__module__]!r}") trace.warning( - "Previously this command was registered from %r" - % sys.modules[previous.__module__] + "Previously this command was registered from {!r}".format(sys.modules[previous.__module__]) ) for a in cmd.aliases: self._alias_dict[a] = k_unsquished diff --git a/breezy/config.py b/breezy/config.py index 51ab3c3f6d..8db0b42bb2 100644 --- a/breezy/config.py +++ b/breezy/config.py @@ -1787,8 +1787,8 @@ def get_password( password = credentials["password"] if password is not None and scheme == "ssh": trace.warning( - "password ignored in section [%s]," - " use an ssh agent instead" % credentials["name"] + "password ignored in section [{}]," + " use an ssh agent instead".format(credentials["name"]) ) password = None else: @@ -2419,7 +2419,7 @@ def _check_option_name(self, option_name): Args: option_name: The name to validate. """ - if _option_ref_re.match("{%s}" % option_name) is None: + if _option_ref_re.match("{{{}}}".format(option_name)) is None: raise IllegalOptionName(option_name) def register(self, option): diff --git a/breezy/controldir.py b/breezy/controldir.py index bd72e45d75..7b73723a7b 100644 --- a/breezy/controldir.py +++ b/breezy/controldir.py @@ -1012,7 +1012,7 @@ def create(klass, base, format=None, possible_transports=None): if klass is not ControlDir: raise AssertionError( "ControlDir.create always creates the" - "default format, not one of %r" % klass + "default format, not one of {!r}".format(klass) ) t = _mod_transport.get_transport(base, possible_transports) t.ensure_base() diff --git a/breezy/crash.py b/breezy/crash.py index fe72d2f4cb..1664b35fca 100644 --- a/breezy/crash.py +++ b/breezy/crash.py @@ -137,9 +137,8 @@ def report_bug_to_apport(exc_info, stderr): stderr.write( "\n" "You can report this problem to Breezy's developers by running\n" - " apport-bug %s\n" - "if a bug-reporting window does not automatically appear.\n" - % (crash_filename) + " apport-bug {}\n" + "if a bug-reporting window does not automatically appear.\n".format(crash_filename) ) # XXX: on Windows, Mac, and other platforms where we might have the # apport libraries but not have an apport always running, we could diff --git a/breezy/directory_service.py b/breezy/directory_service.py index 8ff7c9d3e9..2d7fc96ae6 100644 --- a/breezy/directory_service.py +++ b/breezy/directory_service.py @@ -178,11 +178,11 @@ def help_text(cls, topic): The aliases are:: -%s +{} For example, to push to the parent location:: brz push :parent -""" % "".join(alias_lines) +""".format("".join(alias_lines)) directories.register(":", AliasDirectory, "Easy access to remembered branch locations") diff --git a/breezy/git/transform.py b/breezy/git/transform.py index 3f0d7b8ea0..2ed2757a85 100644 --- a/breezy/git/transform.py +++ b/breezy/git/transform.py @@ -667,8 +667,7 @@ def commit( parent_ids.extend(merge_parents) if self._tree.get_revision_id() != last_rev_id: raise ValueError( - "TreeTransform not based on branch basis: %s" - % self._tree.get_revision_id().decode("utf-8") + "TreeTransform not based on branch basis: {}".format(self._tree.get_revision_id().decode("utf-8")) ) from .. import commit diff --git a/breezy/info.py b/breezy/info.py index 9f576147c9..c51ace2a27 100644 --- a/breezy/info.py +++ b/breezy/info.py @@ -204,7 +204,7 @@ def _show_format_info( outfile.write(f" branch: {branch._format.get_format_description()}\n") if repository: outfile.write( - " repository: %s\n" % repository._format.get_format_description() + " repository: {}\n".format(repository._format.get_format_description()) ) @@ -316,11 +316,11 @@ def _show_branch_stats(branch, verbose, outfile): age = int((time.time() - timestamp) / 3600 / 24) outfile.write(" %8d day%s old\n" % (age, plural(age))) outfile.write( - " first revision: %s\n" % osutils.format_date(timestamp, timezone) + " first revision: {}\n".format(osutils.format_date(timestamp, timezone)) ) timestamp, timezone = stats["latestrev"] outfile.write( - " latest revision: %s\n" % osutils.format_date(timestamp, timezone) + " latest revision: {}\n".format(osutils.format_date(timestamp, timezone)) ) return stats diff --git a/breezy/log.py b/breezy/log.py index d28650aa38..2d08f2787e 100644 --- a/breezy/log.py +++ b/breezy/log.py @@ -1868,7 +1868,7 @@ def log_revision(self, revision): to_file = self.to_file tags = "" if revision.tags: - tags = " {%s}" % (", ".join(sorted(revision.tags))) + tags = " {{{}}}".format(", ".join(sorted(revision.tags))) to_file.write( indent + "%*s %s\t%s%s%s\n" @@ -1982,7 +1982,7 @@ def log_string(self, revno, rev, max_chars, tags=None, prefix=""): if len(rev.parent_ids) > 1: out.append("[merge]") if tags: - tag_str = "{%s}" % (", ".join(sorted(tags))) + tag_str = "{{{}}}".format(", ".join(sorted(tags))) out.append(tag_str) out.append(rev.get_summary()) return self.truncate(prefix + " ".join(out).rstrip("\n"), max_chars) diff --git a/breezy/lsprof.py b/breezy/lsprof.py index 3be99c05ee..a78a2f2c19 100644 --- a/breezy/lsprof.py +++ b/breezy/lsprof.py @@ -10,9 +10,8 @@ import pickle import sys import threading -from typing import Dict, TextIO - from _lsprof import Profiler, profiler_entry +from typing import Dict, TextIO from . import errors diff --git a/breezy/mail_client.py b/breezy/mail_client.py index 056ecdfe2a..021837f03c 100644 --- a/breezy/mail_client.py +++ b/breezy/mail_client.py @@ -539,9 +539,9 @@ def _get_compose_commandline(self, to, subject, attach_path): _subject = "nil" if to is not None: - _to = '"%s"' % self._encode_safe(to).replace('"', '\\"') + _to = '"{}"'.format(self._encode_safe(to).replace('"', '\\"')) if subject is not None: - _subject = '"%s"' % self._encode_safe(subject).replace('"', '\\"') + _subject = '"{}"'.format(self._encode_safe(subject).replace('"', '\\"')) # Funcall the default mail composition function # This will work with any mail mode including default mail-mode @@ -556,9 +556,9 @@ def _get_compose_commandline(self, to, subject, attach_path): elisp = self._prepare_send_function() self.elisp_tmp_file = elisp lmmform = f'(load "{elisp}")' - mmform = '(bzr-add-mime-att "%s")' % self._encode_path( + mmform = '(bzr-add-mime-att "{}")'.format(self._encode_path( attach_path, "attachment" - ) + )) rmform = f'(delete-file "{elisp}")' commandline.append(lmmform) commandline.append(mmform) @@ -615,13 +615,13 @@ def _get_compose_commandline(self, to, subject, attach_path, body=None, from_=No os.write(fd, "tell newMessage\n") if to is not None: os.write( - fd, "make new to recipient with properties" ' {address:"%s"}\n' % to + fd, "make new to recipient with properties" ' {{address:"{}"}}\n'.format(to) ) if from_ is not None: # though from_ doesn't actually seem to be used - os.write(fd, 'set sender to "%s"\n' % from_.replace('"', '\\"')) + os.write(fd, 'set sender to "{}"\n'.format(from_.replace('"', '\\"'))) if subject is not None: - os.write(fd, 'set subject to "%s"\n' % subject.replace('"', '\\"')) + os.write(fd, 'set subject to "{}"\n'.format(subject.replace('"', '\\"'))) if body is not None: # FIXME: would be nice to prepend the body to the # existing content (e.g., preserve signature), but @@ -629,8 +629,7 @@ def _get_compose_commandline(self, to, subject, attach_path, body=None, from_=No # incantation. os.write( fd, - 'set content to "%s\\n\n"\n' - % body.replace('"', '\\"').replace("\n", "\\n"), + 'set content to "{}\\n\n"\n'.format(body.replace('"', '\\"').replace("\n", "\\n")), ) if attach_path is not None: @@ -641,9 +640,8 @@ def _get_compose_commandline(self, to, subject, attach_path, body=None, from_=No os.write( fd, "tell content to make new attachment" - ' with properties {file name:"%s"}' - " at after the last paragraph\n" - % self._encode_path(attach_path, "attachment"), + ' with properties {{file name:"{}"}}' + " at after the last paragraph\n".format(self._encode_path(attach_path, "attachment")), ) os.write(fd, "set visible to true\n") os.write(fd, "end tell\n") diff --git a/breezy/merge.py b/breezy/merge.py index b8479db20f..bd2db2fa76 100644 --- a/breezy/merge.py +++ b/breezy/merge.py @@ -588,7 +588,7 @@ def find_base(self): if self.base_rev_id in lcas: trace.mutter( "Unable to find unique lca. " - "Fallback %r as best option." % self.base_rev_id + "Fallback {!r} as best option.".format(self.base_rev_id) ) interesting_revision_ids = set(lcas) interesting_revision_ids.add(self.base_rev_id) @@ -645,14 +645,14 @@ def make_merger(self): elif self.reprocess: raise errors.BzrError( "Conflict reduction is not supported for merge" - " type %s." % self.merge_type + " type {}.".format(self.merge_type) ) if self.merge_type.supports_show_base: kwargs["show_base"] = self.show_base elif self.show_base: raise errors.BzrError( "Showing base is not supported for this" - " merge type. %s" % self.merge_type + " merge type. {}".format(self.merge_type) ) if ( not getattr(self.merge_type, "supports_reverse_cherrypick", True) @@ -1346,8 +1346,7 @@ def _merge_names(self, trans_id, file_id, paths, parents, names, resolver): # the tree root. if names[self.winner_idx[parent_id_winner]] != "": raise AssertionError( - "File looks like a root, but named %s" - % names[self.winner_idx[parent_id_winner]] + "File looks like a root, but named {}".format(names[self.winner_idx[parent_id_winner]]) ) parent_trans_id = transform.ROOT_PARENT else: diff --git a/breezy/mergetools.py b/breezy/mergetools.py index 6f23515906..fa103bf581 100644 --- a/breezy/mergetools.py +++ b/breezy/mergetools.py @@ -103,7 +103,7 @@ def _subst_filename(args, filename): for arg in args: if "{this_temp}" in arg and "this_temp" not in subst_names: fh, tmp_file = tempfile.mkstemp( - "_bzr_mergetools_%s.THIS" % os.path.basename(filename) + "_bzr_mergetools_{}.THIS".format(os.path.basename(filename)) ) trace.mutter("fh=%r, tmp_file=%r", fh, tmp_file) os.close(fh) diff --git a/breezy/msgeditor.py b/breezy/msgeditor.py index 9eae9f36a7..f34742659f 100644 --- a/breezy/msgeditor.py +++ b/breezy/msgeditor.py @@ -80,8 +80,8 @@ def _run_editor(filename): break raise BzrError( "Could not start any editor.\nPlease specify one with:\n" - " - $BRZ_EDITOR\n - editor=/some/path in %s\n" - " - $VISUAL\n - $EDITOR" % bedding.config_path() + " - $BRZ_EDITOR\n - editor=/some/path in {}\n" + " - $VISUAL\n - $EDITOR".format(bedding.config_path()) ) diff --git a/breezy/plugins/bash_completion/bashcomp.py b/breezy/plugins/bash_completion/bashcomp.py index 1ce931d821..5544cc8cf9 100644 --- a/breezy/plugins/bash_completion/bashcomp.py +++ b/breezy/plugins/bash_completion/bashcomp.py @@ -342,9 +342,9 @@ def command(self, name): cmd_data.options.extend(self.option(opt)) if name == "help" or "help" in cmd.aliases: - cmd_data.fixed_words = "($cmds %s)" % " ".join( + cmd_data.fixed_words = "($cmds {})".format(" ".join( sorted(help_topics.topic_registry.keys()) - ) + )) return cmd_data diff --git a/breezy/plugins/fastimport/bzr_commit_handler.py b/breezy/plugins/fastimport/bzr_commit_handler.py index bbff3ad0ac..18a8ba5421 100644 --- a/breezy/plugins/fastimport/bzr_commit_handler.py +++ b/breezy/plugins/fastimport/bzr_commit_handler.py @@ -850,7 +850,7 @@ def _rename_pending_change( symlink_target=old_ie.symlink_target, ) else: - raise AssertionError("unknown kind: %s" % kind) + raise AssertionError("unknown kind: {}".format(kind)) # Record it self.record_new(new_path, ie) diff --git a/breezy/plugins/weave_fmt/test_bzrdir.py b/breezy/plugins/weave_fmt/test_bzrdir.py index f39eb6c1c8..20739101bc 100644 --- a/breezy/plugins/weave_fmt/test_bzrdir.py +++ b/breezy/plugins/weave_fmt/test_bzrdir.py @@ -574,7 +574,7 @@ def test_unbind_format_6_bzrdir(self): cwd = urlutils.local_path_to_url(getcwd()) self.assertEqual( "brz: ERROR: To use this feature you must " - "upgrade your branch at %s/.\n" % cwd, + "upgrade your branch at {}/.\n".format(cwd), err, ) diff --git a/breezy/plugins/webdav/tests/dav_server.py b/breezy/plugins/webdav/tests/dav_server.py index 6c305d56c1..87dcd54a23 100644 --- a/breezy/plugins/webdav/tests/dav_server.py +++ b/breezy/plugins/webdav/tests/dav_server.py @@ -73,7 +73,7 @@ def read_body(self): encoding = self.headers.get("Transfer-Encoding") if encoding is not None: if encoding != "chunked": - raise AssertionError("Unsupported transfer encoding: %s" % encoding) + raise AssertionError("Unsupported transfer encoding: {}".format(encoding)) body = [] # We receive the content by chunk while True: diff --git a/breezy/plugins/zsh_completion/zshcomp.py b/breezy/plugins/zsh_completion/zshcomp.py index 212b022e0b..e6bed5b14a 100644 --- a/breezy/plugins/zsh_completion/zshcomp.py +++ b/breezy/plugins/zsh_completion/zshcomp.py @@ -186,9 +186,9 @@ def command(self, name): cmd_data.options.extend(self.option(opt)) if name == "help" or "help" in cmd.aliases: - cmd_data.fixed_words = "($cmds %s)" % " ".join( + cmd_data.fixed_words = "($cmds {})".format(" ".join( sorted(help_topics.topic_registry.keys()) - ) + )) return cmd_data diff --git a/breezy/push.py b/breezy/push.py index fbc55f17e5..696028e51b 100644 --- a/breezy/push.py +++ b/breezy/push.py @@ -203,8 +203,8 @@ def _show_push_branch( if push_result.workingtree_updated is False: warning( "This transport does not update the working " - "tree of: %s. See 'brz help working-trees' for " - "more information." % push_result.target_branch.base + "tree of: {}. See 'brz help working-trees' for " + "more information.".format(push_result.target_branch.base) ) push_result.report(to_file) if verbose: diff --git a/breezy/symbol_versioning.py b/breezy/symbol_versioning.py index a85f19be69..189b7dddc3 100644 --- a/breezy/symbol_versioning.py +++ b/breezy/symbol_versioning.py @@ -48,9 +48,9 @@ def deprecated_in(version_tuple): >>> deprecated_in((1, 4, 0)) '%s was deprecated in version 1.4.0.' """ - return "%%s was deprecated in version %s." % breezy._format_version_tuple( + return "%s was deprecated in version {}.".format(breezy._format_version_tuple( version_tuple - ) + )) def set_warning_method(method): diff --git a/breezy/tests/blackbox/test_branch.py b/breezy/tests/blackbox/test_branch.py index 67eb6908c1..3984ded1dc 100644 --- a/breezy/tests/blackbox/test_branch.py +++ b/breezy/tests/blackbox/test_branch.py @@ -463,7 +463,7 @@ def test_branch_stacked_branch_stacked(self): out, err = self.run_bzr(["branch", "branch", "--stacked", "branch2"]) self.assertEqual("", out) self.assertEqual( - "Created new stacked branch referring to %s.\n" % branch_tree.branch.base, + "Created new stacked branch referring to {}.\n".format(branch_tree.branch.base), err, ) self.assertEqual( @@ -486,7 +486,7 @@ def test_branch_stacked(self): out, err = self.run_bzr(["branch", "--stacked", "mainline", "newbranch"]) self.assertEqual("", out) self.assertEqual( - "Created new stacked branch referring to %s.\n" % trunk_tree.branch.base, + "Created new stacked branch referring to {}.\n".format(trunk_tree.branch.base), err, ) self.assertRevisionNotInRepository("newbranch", original_revid) diff --git a/breezy/tests/blackbox/test_info.py b/breezy/tests/blackbox/test_info.py index e8bc2eebe6..d83514b7a6 100644 --- a/breezy/tests/blackbox/test_info.py +++ b/breezy/tests/blackbox/test_info.py @@ -1350,9 +1350,9 @@ def locked_message(a_bool): tree_data = "" extra_space = "" if light_checkout: - tree_data = " light checkout root: %s\n" % friendly_location( + tree_data = " light checkout root: {}\n".format(friendly_location( lco_tree.controldir.root_transport.base - ) + )) extra_space = " " if lco_tree.branch.get_bound_location() is not None: tree_data += "{} checkout root: {}\n".format( @@ -1371,8 +1371,7 @@ def locked_message(a_bool): ) else: branch_data = ( - " checkout of branch: %s\n" - % lco_tree.branch.controldir.root_transport.base + " checkout of branch: {}\n".format(lco_tree.branch.controldir.root_transport.base) ) verbose_info = " 0 committers\n" if verbose >= 2 else "" diff --git a/breezy/tests/blackbox/test_missing.py b/breezy/tests/blackbox/test_missing.py index 1093dab77b..62bd86ed41 100644 --- a/breezy/tests/blackbox/test_missing.py +++ b/breezy/tests/blackbox/test_missing.py @@ -23,9 +23,9 @@ class TestMissing(tests.TestCaseWithTransport): def assertMessages(self, out, must_have=(), must_not_have=()): """Check if commit messages are in or not in the output.""" for m in must_have: - self.assertContainsRe(out, r"\nmessage:\n %s\n" % m) + self.assertContainsRe(out, r"\nmessage:\n {}\n".format(m)) for m in must_not_have: - self.assertNotContainsRe(out, r"\nmessage:\n %s\n" % m) + self.assertNotContainsRe(out, r"\nmessage:\n {}\n".format(m)) def test_missing_quiet(self): # @@ -215,7 +215,7 @@ def test_missing_check_last_location(self): # check last location lines, err = self.run_bzr("missing", working_dir="b") self.assertEqual( - "Using saved parent location: %s\n" "Branches are up to date.\n" % location, + "Using saved parent location: {}\n" "Branches are up to date.\n".format(location), lines, ) self.assertEqual("", err) diff --git a/breezy/tests/blackbox/test_push.py b/breezy/tests/blackbox/test_push.py index f61da9cec3..92a03a3511 100644 --- a/breezy/tests/blackbox/test_push.py +++ b/breezy/tests/blackbox/test_push.py @@ -70,8 +70,7 @@ def test_push_suggests_parent_alias(self): "", "brz: ERROR: No push location known or specified. " "To push to the parent branch " - "(at %s), use 'brz push :parent'.\n" - % urlutils.unescape_for_display(tree_b.branch.base, "utf-8"), + "(at {}), use 'brz push :parent'.\n".format(urlutils.unescape_for_display(tree_b.branch.base, "utf-8")), ), ) @@ -135,9 +134,9 @@ def test_push_remember(self): path = branch_a.get_push_location() self.assertEqual( err, - "Using saved push location: %s\n" + "Using saved push location: {}\n" "All changes applied successfully.\n" - "Pushed up to revision 2.\n" % urlutils.local_path_from_url(path), + "Pushed up to revision 2.\n".format(urlutils.local_path_from_url(path)), ) self.assertEqual(path, branch_b.controldir.root_transport.base) # test explicit --remember @@ -191,9 +190,8 @@ def test_push_quiet(self): push_loc = t.branch.controldir.open_branch().get_push_location() out, err = self.run_bzr("push", working_dir="tree") self.assertEqual( - "Using saved push location: %s\n" - "No new revisions or tags to push.\n" - % urlutils.local_path_from_url(push_loc), + "Using saved push location: {}\n" + "No new revisions or tags to push.\n".format(urlutils.local_path_from_url(push_loc)), err, ) out, err = self.run_bzr("push -q", working_dir="tree") @@ -443,7 +441,7 @@ def test_push_new_branch_stacked_on(self): ) self.assertEqual("", out) self.assertEqual( - "Created new stacked branch referring to %s.\n" % trunk_tree.branch.base, + "Created new stacked branch referring to {}.\n".format(trunk_tree.branch.base), err, ) self.assertPublished(branch_tree.last_revision(), trunk_tree.branch.base) @@ -467,7 +465,7 @@ def look_up(self, name, url, purpose=None): ) self.assertEqual("", out) self.assertEqual( - "Created new stacked branch referring to %s.\n" % trunk_tree.branch.base, + "Created new stacked branch referring to {}.\n".format(trunk_tree.branch.base), err, ) self.assertPublished(branch_tree.last_revision(), trunk_tree.branch.base) @@ -482,7 +480,7 @@ def test_push_new_branch_stacked_uses_parent_when_no_public_url(self): ) self.assertEqual("", out) self.assertEqual( - "Created new stacked branch referring to %s.\n" % trunk_tree.branch.base, + "Created new stacked branch referring to {}.\n".format(trunk_tree.branch.base), err, ) self.assertPublished(branch_tree.last_revision(), trunk_tree.branch.base) @@ -504,7 +502,7 @@ def test_push_new_branch_stacked_uses_parent_public(self): ) self.assertEqual("", out) self.assertEqual( - "Created new stacked branch referring to %s.\n" % trunk_public_url, err + "Created new stacked branch referring to {}.\n".format(trunk_public_url), err ) self.assertPublished(branch_tree.last_revision(), trunk_public_url) diff --git a/breezy/tests/blackbox/test_status.py b/breezy/tests/blackbox/test_status.py index 85070e99e0..3b2b08afbd 100644 --- a/breezy/tests/blackbox/test_status.py +++ b/breezy/tests/blackbox/test_status.py @@ -822,7 +822,7 @@ def make_uncommitted_tree(self): except UnicodeEncodeError as err: raise TestSkipped( "can't build unicode working tree in " - "filesystem encoding %s" % sys.getfilesystemencoding() + "filesystem encoding {}".format(sys.getfilesystemencoding()) ) from err working_tree.add(filename) return working_tree diff --git a/breezy/tests/blackbox/test_update.py b/breezy/tests/blackbox/test_update.py index 8fcc6f06de..8132d62a4b 100644 --- a/breezy/tests/blackbox/test_update.py +++ b/breezy/tests/blackbox/test_update.py @@ -44,7 +44,7 @@ def test_update_standalone_trivial_with_alias_up(self): self.make_branch_and_tree(".") out, err = self.run_bzr("up") self.assertEqual( - "Tree is up to date at revision 0 of branch %s\n" % self.test_dir, err + "Tree is up to date at revision 0 of branch {}\n".format(self.test_dir), err ) self.assertEqual("", out) @@ -53,8 +53,7 @@ def test_update_up_to_date_light_checkout(self): self.run_bzr("checkout --lightweight branch checkout") out, err = self.run_bzr("update checkout") self.assertEqual( - "Tree is up to date at revision 0 of branch %s\n" - % osutils.pathjoin(self.test_dir, "branch"), + "Tree is up to date at revision 0 of branch {}\n".format(osutils.pathjoin(self.test_dir, "branch")), err, ) self.assertEqual("", out) @@ -86,12 +85,11 @@ def test_update_out_of_date_standalone_tree(self): self.assertEqualDiff( """+N file All changes applied successfully. -Updated to revision 1 of branch %s -""" - % osutils.pathjoin( +Updated to revision 1 of branch {} +""".format(osutils.pathjoin( self.test_dir, "branch", - ), + )), err, ) self.assertPathExists("branch/file") @@ -109,12 +107,11 @@ def test_update_out_of_date_light_checkout(self): self.assertEqualDiff( """+N file All changes applied successfully. -Updated to revision 1 of branch %s -""" - % osutils.pathjoin( +Updated to revision 1 of branch {} +""".format(osutils.pathjoin( self.test_dir, "branch", - ), + )), err, ) self.assertEqual("", out) @@ -140,12 +137,11 @@ def test_update_conflicts_returns_2(self): """ M file Text conflict in file 1 conflicts encountered. -Updated to revision 2 of branch %s -""" - % osutils.pathjoin( +Updated to revision 2 of branch {} +""".format(osutils.pathjoin( self.test_dir, "branch", - ), + )), err, ) self.assertEqual("", out) @@ -187,13 +183,12 @@ def test_smoke_update_checkout_bound_branch_local_commits(self): All changes applied successfully. +N file All changes applied successfully. -Updated to revision 2 of branch %s +Updated to revision 2 of branch {} Your local commits will now show as pending merges with 'brz status', and can be committed with 'brz commit'. -""" - % osutils.pathjoin( +""".format(osutils.pathjoin( self.test_dir, "master", - ), + )), err, ) self.assertEqual([master_tip, child_tip], wt.get_parent_ids()) @@ -243,12 +238,11 @@ def test_update_with_merges(self): self.assertEqualDiff( """+N file3 All changes applied successfully. -Updated to revision 2 of branch %s -""" - % osutils.pathjoin( +Updated to revision 2 of branch {} +""".format(osutils.pathjoin( self.test_dir, "master", - ), + )), err, ) # The pending merges should still be there @@ -297,12 +291,11 @@ def test_update_with_merge_merged_to_master(self): self.assertEqual("", out) self.assertEqualDiff( """All changes applied successfully. -Updated to revision 2 of branch %s -""" - % osutils.pathjoin( +Updated to revision 2 of branch {} +""".format(osutils.pathjoin( self.test_dir, "master", - ), + )), err, ) # The pending merges should still be there diff --git a/breezy/tests/http_server.py b/breezy/tests/http_server.py index f9b70d1652..4c9c48d7a8 100644 --- a/breezy/tests/http_server.py +++ b/breezy/tests/http_server.py @@ -449,8 +449,7 @@ def start_server(self, backing_transport_server=None): or isinstance(backing_transport_server, test_server.LocalURLServer) ): raise AssertionError( - "HTTPServer currently assumes local transport, got %s" - % backing_transport_server + "HTTPServer currently assumes local transport, got {}".format(backing_transport_server) ) self._home_dir = osutils.getcwd() self._local_path_parts = self._home_dir.split(os.path.sep) diff --git a/breezy/tests/per_branch/test_tags.py b/breezy/tests/per_branch/test_tags.py index 2b1dbc11a2..fa29a2e6b1 100644 --- a/breezy/tests/per_branch/test_tags.py +++ b/breezy/tests/per_branch/test_tags.py @@ -444,7 +444,7 @@ def setUp(self): branch = self.make_branch("probe") if branch._format.supports_tags(): raise tests.TestSkipped( - "Format %s declares that tags are supported" % branch._format + "Format {} declares that tags are supported".format(branch._format) ) # it's covered by TestBranchTags diff --git a/breezy/tests/per_controldir/test_controldir.py b/breezy/tests/per_controldir/test_controldir.py index 4e9104bca8..e0bff07027 100644 --- a/breezy/tests/per_controldir/test_controldir.py +++ b/breezy/tests/per_controldir/test_controldir.py @@ -52,7 +52,7 @@ def skipIfNoWorkingTree(self, a_controldir): a_controldir.open_workingtree() except (errors.NotLocalUrl, errors.NoWorkingTree) as e: raise TestSkipped( - "bzrdir on transport %r has no working tree" % a_controldir.transport + "bzrdir on transport {!r} has no working tree".format(a_controldir.transport) ) from e def openWorkingTreeIfLocal(self, a_controldir): @@ -72,7 +72,7 @@ def createWorkingTreeOrSkip(self, a_controldir): return a_controldir.create_workingtree() except (errors.NotLocalUrl, errors.UnsupportedOperation) as e: raise TestSkipped( - "cannot make working tree with transport %r" % a_controldir.transport + "cannot make working tree with transport {!r}".format(a_controldir.transport) ) from e def sproutOrSkip( @@ -130,7 +130,7 @@ def test_create_null_workingtree(self): wt = dir.create_workingtree(revision_id=_mod_revision.NULL_REVISION) except (errors.NotLocalUrl, errors.UnsupportedOperation) as e: raise TestSkipped( - "cannot make working tree with transport %r" % dir.transport + "cannot make working tree with transport {!r}".format(dir.transport) ) from e self.assertEqual([], wt.get_parent_ids()) diff --git a/breezy/tests/per_interrepository/test_interrepository.py b/breezy/tests/per_interrepository/test_interrepository.py index f7d38c04f5..c0d850a335 100644 --- a/breezy/tests/per_interrepository/test_interrepository.py +++ b/breezy/tests/per_interrepository/test_interrepository.py @@ -35,7 +35,7 @@ def check_repo_format_for_funky_id_on_win32(repo): if not repo._format.supports_funky_characters and sys.platform == "win32": raise TestSkipped( "funky chars not allowed on this platform in repository" - " %s" % repo.__class__.__name__ + " {}".format(repo.__class__.__name__) ) diff --git a/breezy/tests/per_repository/test_fetch.py b/breezy/tests/per_repository/test_fetch.py index 80a1072ea3..d49f508257 100644 --- a/breezy/tests/per_repository/test_fetch.py +++ b/breezy/tests/per_repository/test_fetch.py @@ -88,7 +88,7 @@ def test_fetch_to_knit3(self): tree_b = b_branch.create_checkout("b", lightweight=True) except errors.NotLocalUrl as err: raise TestSkipped( - "cannot make working tree with transport %r" % b_bzrdir.transport + "cannot make working tree with transport {!r}".format(b_bzrdir.transport) ) from err rev2 = tree_b.commit("no change") rev2_tree = knit3_repo.revision_tree(rev2) diff --git a/breezy/tests/per_transport.py b/breezy/tests/per_transport.py index 55b27fe7a2..bcbd5e9801 100644 --- a/breezy/tests/per_transport.py +++ b/breezy/tests/per_transport.py @@ -48,8 +48,7 @@ def get_transport_test_permutations(module): """Get the permutations module wants to have tested.""" if getattr(module, "get_test_permutations", None) is None: raise AssertionError( - "transport module %s doesn't provide get_test_permutations()" - % module.__name__ + "transport module {} doesn't provide get_test_permutations()".format(module.__name__) ) return [] return module.get_test_permutations() @@ -957,7 +956,7 @@ def test_connection_error(self): url = self._server.get_bogus_url() except NotImplementedError as err: raise TestSkipped( - "Transport %s has no bogus URL support." % self._server.__class__ + "Transport {} has no bogus URL support.".format(self._server.__class__) ) from err t = _mod_transport.get_transport_from_url(url) self.assertRaises((ConnectionError, NoSuchFile), t.get, ".bzr/branch") @@ -1019,7 +1018,7 @@ def test_hardlink(self): pass except TransportNotPossible as err: raise TestSkipped( - "Transport %s does not support hardlinks." % self._server.__class__ + "Transport {} does not support hardlinks.".format(self._server.__class__) ) from err def test_symlink(self): @@ -1044,7 +1043,7 @@ def test_symlink(self): ) except TransportNotPossible as err: raise TestSkipped( - "Transport %s does not support symlinks." % self._server.__class__ + "Transport {} does not support symlinks.".format(self._server.__class__) ) from err self.assertEqual(source_name, t.readlink(link_name)) @@ -1055,7 +1054,7 @@ def test_readlink_nonexistent(self): self.assertRaises(NoSuchFile, t.readlink, "nonexistent") except TransportNotPossible as err: raise TestSkipped( - "Transport %s does not support symlinks." % self._server.__class__ + "Transport {} does not support symlinks.".format(self._server.__class__) ) from err def test_list_dir(self): diff --git a/breezy/tests/per_workingtree/test_eol_conversion.py b/breezy/tests/per_workingtree/test_eol_conversion.py index 79c412e57d..fcf94edd5d 100644 --- a/breezy/tests/per_workingtree/test_eol_conversion.py +++ b/breezy/tests/per_workingtree/test_eol_conversion.py @@ -45,8 +45,8 @@ def setUp(self): f = fmt.supports_content_filtering if f is None: raise TestSkipped( - "format %s doesn't declare whether it " - "supports content filtering, assuming not" % fmt + "format {} doesn't declare whether it " + "supports content filtering, assuming not".format(fmt) ) if not f(): raise TestSkipped(f"format {fmt} doesn't support content filtering") diff --git a/breezy/tests/per_workingtree/test_pull.py b/breezy/tests/per_workingtree/test_pull.py index e5196331b9..f8cd19423e 100644 --- a/breezy/tests/per_workingtree/test_pull.py +++ b/breezy/tests/per_workingtree/test_pull.py @@ -108,7 +108,7 @@ def make_branch_deleting_dir(self, relpath=None): def test_pull_orphans(self): if not self.workingtree_format.missing_parent_conflicts: raise tests.TestSkipped( - "%r does not support missing parent conflicts" % self.workingtree_format + "{!r} does not support missing parent conflicts".format(self.workingtree_format) ) trunk = self.make_branch_deleting_dir("trunk") work = trunk.controldir.sprout("work", revision_id=b"2").open_workingtree() diff --git a/breezy/tests/per_workingtree/test_views.py b/breezy/tests/per_workingtree/test_views.py index cb74da5779..38a03ceeaf 100644 --- a/breezy/tests/per_workingtree/test_views.py +++ b/breezy/tests/per_workingtree/test_views.py @@ -35,8 +35,8 @@ def setUp(self): f = fmt.supports_views if f is None: raise TestSkipped( - "format %s doesn't declare whether it " - "supports views, assuming not" % fmt + "format {} doesn't declare whether it " + "supports views, assuming not".format(fmt) ) if not f(): raise TestNotApplicable(f"format {fmt} doesn't support views") diff --git a/breezy/tests/per_workingtree/test_workingtree.py b/breezy/tests/per_workingtree/test_workingtree.py index 9675a8d9cc..483a71ed8c 100644 --- a/breezy/tests/per_workingtree/test_workingtree.py +++ b/breezy/tests/per_workingtree/test_workingtree.py @@ -301,7 +301,7 @@ def test_rename_dirs(self): wt.commit("create initial state") revid = b.last_revision() - self.log("first revision_id is {%s}" % revid) + self.log("first revision_id is {{{}}}".format(revid)) tree = b.repository.revision_tree(revid) self.log(f"contents of tree: {list(tree.iter_entries_by_dir())!r}") diff --git a/breezy/tests/test_config.py b/breezy/tests/test_config.py index 1bb361aa44..4e3b5cbe3d 100644 --- a/breezy/tests/test_config.py +++ b/breezy/tests/test_config.py @@ -1946,7 +1946,7 @@ def test_save_hook_remote_bzrdir(self): class TestOptionNames(tests.TestCase): def is_valid(self, name): - return config._option_ref_re.match("{%s}" % name) is not None + return config._option_ref_re.match("{{{}}}".format(name)) is not None def test_valid_names(self): self.assertTrue(self.is_valid("foo")) @@ -2595,8 +2595,7 @@ def get_bytes(relpath): self.assertEqual( warnings, [ - "Permission denied while trying to load configuration store %s." - % store.external_url() + "Permission denied while trying to load configuration store {}.".format(store.external_url()) ], ) diff --git a/breezy/tests/test_email_message.py b/breezy/tests/test_email_message.py index 9c81ba458b..1fd2060797 100644 --- a/breezy/tests/test_email_message.py +++ b/breezy/tests/test_email_message.py @@ -32,15 +32,14 @@ _SIMPLE_MESSAGE = ( """\ MIME-Version: 1.0 -Content-Type: text/plain; charset="%%s" -Content-Transfer-Encoding: %%s +Content-Type: text/plain; charset="%s" +Content-Transfer-Encoding: %s From: from@from.com Subject: subject To: to@to.com -User-Agent: Bazaar (%s) +User-Agent: Bazaar ({}) -%%s""" - % _breezy_version +%s""".format(_breezy_version) ) SIMPLE_MESSAGE_ASCII = _SIMPLE_MESSAGE % ("us-ascii", "7bit", "body") diff --git a/breezy/tests/test_errors.py b/breezy/tests/test_errors.py index 9b5712ee09..0a2da14f2a 100644 --- a/breezy/tests/test_errors.py +++ b/breezy/tests/test_errors.py @@ -45,7 +45,7 @@ def test_no_arg_named_message(self): ) if fmt and fmt_pattern.search(fmt): self.assertFalse( - True, ('"message" not allowed in ' '"errors.%s._fmt"' % c.__name__) + True, ('"message" not allowed in ' '"errors.{}._fmt"'.format(c.__name__)) ) def test_duplicate_help_prefix(self): @@ -463,9 +463,8 @@ def test_corrupt_repository(self): repo = self.make_repository(".") error = errors.CorruptRepository(repo) self.assertEqualDiff( - "An error has been detected in the repository %s.\n" - "Please run brz reconcile on this repository." - % repo.controldir.root_transport.base, + "An error has been detected in the repository {}.\n" + "Please run brz reconcile on this repository.".format(repo.controldir.root_transport.base), str(error), ) diff --git a/breezy/tests/test_http.py b/breezy/tests/test_http.py index d8bf90ca5f..61cf502876 100644 --- a/breezy/tests/test_http.py +++ b/breezy/tests/test_http.py @@ -1448,7 +1448,7 @@ def test_one_redirection(self): t = self.get_old_transport() new_prefix = f"http://{self.new_server.host}:{self.new_server.port}" self.old_server.redirections = [ - ("(.*)", r"%s/1\1" % (new_prefix), 301), + ("(.*)", r"{}/1\1".format(new_prefix), 301), ] self.assertEqual( b"redirected once", t.request("GET", t._remote_path("a"), retries=1).read() @@ -1459,11 +1459,11 @@ def test_five_redirections(self): old_prefix = f"http://{self.old_server.host}:{self.old_server.port}" new_prefix = f"http://{self.new_server.host}:{self.new_server.port}" self.old_server.redirections = [ - ("/1(.*)", r"%s/2\1" % (old_prefix), 302), - ("/2(.*)", r"%s/3\1" % (old_prefix), 303), - ("/3(.*)", r"%s/4\1" % (old_prefix), 307), - ("/4(.*)", r"%s/5\1" % (new_prefix), 301), - ("(/[^/]+)", r"%s/1\1" % (old_prefix), 301), + ("/1(.*)", r"{}/2\1".format(old_prefix), 302), + ("/2(.*)", r"{}/3\1".format(old_prefix), 303), + ("/3(.*)", r"{}/4\1".format(old_prefix), 307), + ("/4(.*)", r"{}/5\1".format(new_prefix), 301), + ("(/[^/]+)", r"{}/1\1".format(old_prefix), 301), ] self.assertEqual( b"redirected 5 times", @@ -2267,7 +2267,7 @@ def setUp(self): ) new_prefix = f"http://{self.new_server.host}:{self.new_server.port}" self.old_server.redirections = [ - ("(.*)", r"%s/1\1" % (new_prefix), 301), + ("(.*)", r"{}/1\1".format(new_prefix), 301), ] self.old_transport = self.get_old_transport() self.new_server.add_user("joe", "foo") @@ -2309,7 +2309,7 @@ def test_auth_on_redirected_via_following_redirections(self): t = self.old_transport new_prefix = f"http://{self.new_server.host}:{self.new_server.port}" self.old_server.redirections = [ - ("(.*)", r"%s/1\1" % (new_prefix), 301), + ("(.*)", r"{}/1\1".format(new_prefix), 301), ] self.assertEqual( b"redirected once", t.request("GET", t.abspath("a"), retries=3).read() diff --git a/breezy/tests/test_mail_client.py b/breezy/tests/test_mail_client.py index 1576dc9008..1557a529f5 100644 --- a/breezy/tests/test_mail_client.py +++ b/breezy/tests/test_mail_client.py @@ -47,7 +47,7 @@ def test_commandline(self): tbird = mail_client.Thunderbird(None) commandline = tbird._get_compose_commandline(None, None, "file%") self.assertEqual( - ["-compose", "attachment='%s'" % urlutils.local_path_to_url("file%")], + ["-compose", "attachment='{}'".format(urlutils.local_path_to_url("file%"))], commandline, ) commandline = tbird._get_compose_commandline( diff --git a/breezy/tests/test_mergetools.py b/breezy/tests/test_mergetools.py index 30a38ac577..2b34c158a7 100644 --- a/breezy/tests/test_mergetools.py +++ b/breezy/tests/test_mergetools.py @@ -119,7 +119,7 @@ def dummy_invoker(exe, args, cleanup): cleanup(0) return 0 - command = "%s {result}" % os.path.basename(sys.executable) + command = "{} {{result}}".format(os.path.basename(sys.executable)) retcode = mergetools.invoke(command, "test.txt", dummy_invoker) self.assertEqual(0, retcode) self.assertEqual(sys.executable, self._exe) diff --git a/breezy/tests/test_msgeditor.py b/breezy/tests/test_msgeditor.py index 21067bb391..9f91f9c4fc 100644 --- a/breezy/tests/test_msgeditor.py +++ b/breezy/tests/test_msgeditor.py @@ -57,7 +57,7 @@ def make_uncommitted_tree(self): except UnicodeEncodeError: self.skipTest( "can't build unicode working tree in " - "filesystem encoding %s" % sys.getfilesystemencoding() + "filesystem encoding {}".format(sys.getfilesystemencoding()) ) working_tree.add(filename) return working_tree @@ -357,7 +357,7 @@ def test_unsupported_encoding_commit_message(self): if char is None: self.skipTest( "Cannot find suitable non-ascii character " - "for user_encoding (%s)" % osutils.get_user_encoding() + "for user_encoding ({})".format(osutils.get_user_encoding()) ) self.make_fake_editor(message=char) diff --git a/breezy/tests/test_source.py b/breezy/tests/test_source.py index 5223306cc4..9f74bf6693 100644 --- a/breezy/tests/test_source.py +++ b/breezy/tests/test_source.py @@ -154,8 +154,8 @@ def test_tmpdir_not_in_source_files(self): for filename in self.get_source_files(): if re.search(r"test....\.tmp", filename): self.fail( - "get_source_file() returned filename %r " - "from within a temporary directory" % filename + "get_source_file() returned filename {!r} " + "from within a temporary directory".format(filename) ) def test_copyright(self): @@ -257,7 +257,7 @@ def _format_message(self, dict_, message): for f, lines in dict_.items() ] ) - return message + "\n\n %s" % ("\n ".join(files)) + return message + "\n\n {}".format("\n ".join(files)) def test_coding_style(self): """Check if bazaar code conforms to some coding style conventions. @@ -307,7 +307,7 @@ def test_coding_style(self): problems.append( "The following source files doesn't have a " "newline at the end:" - "\n\n %s" % ("\n ".join(no_newline_at_eof)) + "\n\n {}".format("\n ".join(no_newline_at_eof)) ) if problems: self.fail("\n\n".join(problems)) @@ -330,8 +330,7 @@ def test_no_asserts(self): break if badfiles: self.fail( - "these files contain an assert statement and should not:\n%s" - % "\n".join(badfiles) + "these files contain an assert statement and should not:\n{}".format("\n".join(badfiles)) ) def test_extension_exceptions(self): diff --git a/breezy/tests/test_version.py b/breezy/tests/test_version.py index 4fd19fa939..bef69c6fac 100644 --- a/breezy/tests/test_version.py +++ b/breezy/tests/test_version.py @@ -65,6 +65,6 @@ def test_platform(self): out = self.make_utf8_encoded_stringio() self.overrideAttr(platform, "platform", lambda **kwargs: self._platform) version.show_version(show_config=False, show_copyright=False, to_file=out) - expected = r"(?m)^ Platform: %s" % self._platform + expected = r"(?m)^ Platform: {}".format(self._platform) expected = expected.encode("utf-8") self.assertContainsRe(out.getvalue(), expected) diff --git a/breezy/transport/__init__.py b/breezy/transport/__init__.py index d71832eb93..14c66effc9 100644 --- a/breezy/transport/__init__.py +++ b/breezy/transport/__init__.py @@ -1104,10 +1104,10 @@ def list_dir(self, relpath): it if at all possible. """ raise errors.TransportNotPossible( - "Transport %r has not " + "Transport {!r} has not " "implemented list_dir " "(but must claim to be listable " - "to trigger this error)." % (self) + "to trigger this error).".format(self) ) def lock_read(self, relpath): diff --git a/breezy/transport/gio_transport.py b/breezy/transport/gio_transport.py index 749139ae72..bdd8d38f26 100644 --- a/breezy/transport/gio_transport.py +++ b/breezy/transport/gio_transport.py @@ -221,7 +221,7 @@ def _create_connection(self, credentials=None): self.loop.run() except gio.Error as e: raise errors.TransportError( - msg="Error setting up connection:" " %s" % str(e), orig_error=e + msg="Error setting up connection:" " {}".format(str(e)), orig_error=e ) from e return connection, (user, password) @@ -293,7 +293,7 @@ def put_file(self, relpath, fp, mode=None): :param fp: File-like or string object. """ if debug.debug_flag_enabled("gio"): - mutter("GIO put_file %s" % relpath) + mutter("GIO put_file {}".format(relpath)) tmppath = "%s.tmp.%.9f.%d.%d" % ( relpath, time.time(), @@ -330,7 +330,7 @@ def mkdir(self, relpath, mode=None): """Create a directory at the given path.""" try: if debug.debug_flag_enabled("gio"): - mutter("GIO mkdir: %s" % relpath) + mutter("GIO mkdir: {}".format(relpath)) f = self._get_GIO(relpath) f.make_directory() self._setmode(relpath, mode) @@ -340,7 +340,7 @@ def mkdir(self, relpath, mode=None): def open_write_stream(self, relpath, mode=None): """See Transport.open_write_stream.""" if debug.debug_flag_enabled("gio"): - mutter("GIO open_write_stream %s" % relpath) + mutter("GIO open_write_stream {}".format(relpath)) if mode is not None: self._setmode(relpath, mode) result = GioFileStream(self, relpath) @@ -361,7 +361,7 @@ def rmdir(self, relpath): """Delete the directory at rel_path.""" try: if debug.debug_flag_enabled("gio"): - mutter("GIO rmdir %s" % relpath) + mutter("GIO rmdir {}".format(relpath)) st = self.stat(relpath) if stat.S_ISDIR(st.st_mode): f = self._get_GIO(relpath) @@ -384,7 +384,7 @@ def append_file(self, relpath, file, mode=None): # GIO append_to seems not to append but to truncate # Work around this. if debug.debug_flag_enabled("gio"): - mutter("GIO append_file: %s" % relpath) + mutter("GIO append_file: {}".format(relpath)) tmppath = "%s.tmp.%.9f.%d.%d" % ( relpath, time.time(), @@ -429,7 +429,7 @@ def _setmode(self, relpath, mode): Only set permissions on Unix systems """ if debug.debug_flag_enabled("gio"): - mutter("GIO _setmode %s" % relpath) + mutter("GIO _setmode {}".format(relpath)) if mode: try: f = self._get_GIO(relpath) diff --git a/breezy/transport/http/urllib.py b/breezy/transport/http/urllib.py index 5e5dd95206..c9434aef47 100644 --- a/breezy/transport/http/urllib.py +++ b/breezy/transport/http/urllib.py @@ -749,7 +749,7 @@ def do_open(self, http_class, request, first_try=True): resp.msg = r.reason resp.version = r.version if self._debuglevel >= 2: - print("Create addinfourl: %r" % resp) + print("Create addinfourl: {!r}".format(resp)) print(f" For: {request.get_method()!r}({request.get_full_url()!r})") if debug.debug_flag_enabled("http"): version = "HTTP/%d.%d" @@ -1735,7 +1735,7 @@ def http_error_default(self, req, fp, code, msg, hdrs): if code == 403: raise errors.TransportError( "Server refuses to fulfill the request (403 Forbidden)" - " for %s" % req.get_full_url() + " for {}".format(req.get_full_url()) ) else: raise errors.UnexpectedHttpStatus( diff --git a/breezy/tree.py b/breezy/tree.py index d5ee845dda..98609a0ba6 100644 --- a/breezy/tree.py +++ b/breezy/tree.py @@ -422,7 +422,7 @@ def get_nested_tree(self, path): def kind(self, path): raise NotImplementedError( - "Tree subclass %s must implement kind" % self.__class__.__name__ + "Tree subclass {} must implement kind".format(self.__class__.__name__) ) def stored_kind(self, path): @@ -454,8 +454,8 @@ def path_content_summary(self, path): def get_reference_revision(self, path): raise NotImplementedError( - "Tree subclass %s must implement " - "get_reference_revision" % self.__class__.__name__ + "Tree subclass {} must implement " + "get_reference_revision".format(self.__class__.__name__) ) def _comparison_data(self, entry, path): diff --git a/breezy/ui/__init__.py b/breezy/ui/__init__.py index d7e7cda36f..11ee095da3 100644 --- a/breezy/ui/__init__.py +++ b/breezy/ui/__init__.py @@ -185,7 +185,7 @@ class UIFactory: } def __init__(self) -> None: - self._task_stack: List["ProgressTask"] = [] + self._task_stack: List[ProgressTask] = [] self.suppressed_warnings: Set[str] = set() self._quiet = False @@ -277,7 +277,7 @@ def make_output_stream(self, encoding=None, encoding_type="replace"): def _make_output_stream_explicit(self, encoding, encoding_type): raise NotImplementedError( - "%s doesn't support make_output_stream" % (self.__class__.__name__) + "{} doesn't support make_output_stream".format(self.__class__.__name__) ) def nested_progress_bar(self):