changeset 52636:0e11e532c958

style: use `ui.xxxnoi18n()` methods instead of wrapping msg in `()` These aliases were introduced back in 5209fc94b982, because `black` was going to strip away the extra parentheses, but they're needed to subvert `test-check-code.t`. That obviously changed at some point, but `pyupgrade`[1] also strips these out. While that tool is very useful in adapting code to modern standards, it lacks the ability to turn off most conversions, so constantly reverting these is a pain. Even without that, the code is more understandable with an explicit declaration. It also would have been an easy typo to miss the leading `_` in the i18n method `_()` that the checker is looking for, and fail to detect the problem. The `contrib/perf.py` code just uses a local alias to the original methods because (IIUC), this tries to be compatible with old versions of hg. But practically, these noi18n aliases were added before useful py3 support, and at some point, it won't be feasible to do py2 benchmarking anymore, and maybe this module can be cleaned up some. [1] https://github.com/asottile/pyupgrade
author Matt Harbison <matt_harbison@yahoo.com>
date Mon, 06 Jan 2025 13:29:42 -0500
parents cdfaba964f21
children 3b6f25190157
files contrib/perf.py doc/gendoc.py hgext/convert/cvsps.py hgext/hgk.py hgext/keyword.py hgext/remotefilelog/debugcommands.py hgext/sparse.py mercurial/debugcommands.py mercurial/revlogutils/debug.py mercurial/upgrade.py mercurial/upgrade_utils/actions.py tests/autodiff.py tests/testlib/ext-phase-report.py
diffstat 13 files changed, 80 insertions(+), 103 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/perf.py	Tue Jan 07 14:57:51 2025 -0500
+++ b/contrib/perf.py	Mon Jan 06 13:29:42 2025 -0500
@@ -464,32 +464,29 @@
     # experimental config: perf.all-timing
     displayall = ui.configbool(b"perf", b"all-timing", True)
 
+    # ui.warnnoi18n was introduced in 5209fc94b982
+    ui_warn = ui.warn
+
     # experimental config: perf.run-limits
     limitspec = ui.configlist(b"perf", b"run-limits", [])
     limits = []
     for item in limitspec:
         parts = item.split(b'-', 1)
         if len(parts) < 2:
-            ui.warn((b'malformatted run limit entry, missing "-": %s\n' % item))
+            ui_warn(b'malformatted run limit entry, missing "-": %s\n' % item)
             continue
         try:
             time_limit = float(_sysstr(parts[0]))
         except ValueError as e:
-            ui.warn(
-                (
-                    b'malformatted run limit entry, %s: %s\n'
-                    % (_bytestr(e), item)
-                )
+            ui_warn(
+                b'malformatted run limit entry, %s: %s\n' % (_bytestr(e), item)
             )
             continue
         try:
             run_limit = int(_sysstr(parts[1]))
         except ValueError as e:
-            ui.warn(
-                (
-                    b'malformatted run limit entry, %s: %s\n'
-                    % (_bytestr(e), item)
-                )
+            ui_warn(
+                b'malformatted run limit entry, %s: %s\n' % (_bytestr(e), item)
             )
             continue
         limits.append((time_limit, run_limit))
--- a/doc/gendoc.py	Tue Jan 07 14:57:51 2025 -0500
+++ b/doc/gendoc.py	Mon Jan 06 13:29:42 2025 -0500
@@ -151,14 +151,12 @@
             b"extensions is available in the help system."
         )
     )
-    ui.write(
-        (
-            b"\n\n"
-            b".. contents::\n"
-            b"   :class: htmlonly\n"
-            b"   :local:\n"
-            b"   :depth: 1\n\n"
-        )
+    ui.writenoi18n(
+        b"\n\n"
+        b".. contents::\n"
+        b"   :class: htmlonly\n"
+        b"   :local:\n"
+        b"   :depth: 1\n\n"
     )
 
     for extensionname in sorted(allextensionnames()):
--- a/hgext/convert/cvsps.py	Tue Jan 07 14:57:51 2025 -0500
+++ b/hgext/convert/cvsps.py	Mon Jan 06 13:29:42 2025 -0500
@@ -1002,22 +1002,18 @@
             # Note: trailing spaces on several lines here are needed to have
             #       bug-for-bug compatibility with cvsps.
             ui.write(b'---------------------\n')
-            ui.write((b'PatchSet %d \n' % cs.id))
-            ui.write(
-                (
-                    b'Date: %s\n'
-                    % dateutil.datestr(cs.date, b'%Y/%m/%d %H:%M:%S %1%2')
-                )
+            ui.writenoi18n(b'PatchSet %d \n' % cs.id)
+            ui.writenoi18n(
+                b'Date: %s\n'
+                % dateutil.datestr(cs.date, b'%Y/%m/%d %H:%M:%S %1%2')
             )
-            ui.write((b'Author: %s\n' % cs.author))
-            ui.write((b'Branch: %s\n' % (cs.branch or b'HEAD')))
-            ui.write(
-                (
-                    b'Tag%s: %s \n'
-                    % (
-                        [b'', b's'][len(cs.tags) > 1],
-                        b','.join(cs.tags) or b'(none)',
-                    )
+            ui.writenoi18n(b'Author: %s\n' % cs.author)
+            ui.writenoi18n(b'Branch: %s\n' % (cs.branch or b'HEAD'))
+            ui.writenoi18n(
+                b'Tag%s: %s \n'
+                % (
+                    [b'', b's'][len(cs.tags) > 1],
+                    b','.join(cs.tags) or b'(none)',
                 )
             )
             if cs.branchpoints:
@@ -1026,14 +1022,12 @@
                 )
             if opts[b"parents"] and cs.parents:
                 if len(cs.parents) > 1:
-                    ui.write(
-                        (
-                            b'Parents: %s\n'
-                            % (b','.join([(b"%d" % p.id) for p in cs.parents]))
-                        )
+                    ui.writenoi18n(
+                        b'Parents: %s\n'
+                        % (b','.join([(b"%d" % p.id) for p in cs.parents]))
                     )
                 else:
-                    ui.write((b'Parent: %d\n' % cs.parents[0].id))
+                    ui.writenoi18n(b'Parent: %d\n' % cs.parents[0].id)
 
             if opts[b"ancestors"]:
                 b = cs.branch
@@ -1042,7 +1036,7 @@
                     b, c = ancestors[b]
                     r.append(b'%s:%d:%d' % (b or b"HEAD", c, branches[b]))
                 if r:
-                    ui.write((b'Ancestors: %s\n' % (b','.join(r))))
+                    ui.writenoi18n(b'Ancestors: %s\n' % (b','.join(r)))
 
             ui.writenoi18n(b'Log:\n')
             ui.write(b'%s\n\n' % cs.comment)
--- a/hgext/hgk.py	Tue Jan 07 14:57:51 2025 -0500
+++ b/hgext/hgk.py	Mon Jan 06 13:29:42 2025 -0500
@@ -152,23 +152,23 @@
     if ctx is None:
         ctx = repo[n]
     # use ctx.node() instead ??
-    ui.write((b"tree %s\n" % short(ctx.changeset()[0])))
+    ui.writenoi18n(b"tree %s\n" % short(ctx.changeset()[0]))
     for p in ctx.parents():
-        ui.write((b"parent %s\n" % p))
+        ui.writenoi18n(b"parent %s\n" % p)
 
     date = ctx.date()
     description = ctx.description().replace(b"\0", b"")
-    ui.write((b"author %s %d %d\n" % (ctx.user(), int(date[0]), date[1])))
+    ui.writenoi18n(b"author %s %d %d\n" % (ctx.user(), int(date[0]), date[1]))
 
     if b'committer' in ctx.extra():
-        ui.write((b"committer %s\n" % ctx.extra()[b'committer']))
+        ui.writenoi18n(b"committer %s\n" % ctx.extra()[b'committer'])
 
-    ui.write((b"revision %d\n" % ctx.rev()))
-    ui.write((b"branch %s\n" % ctx.branch()))
+    ui.writenoi18n(b"revision %d\n" % ctx.rev())
+    ui.writenoi18n(b"branch %s\n" % ctx.branch())
     if obsolete.isenabled(repo, obsolete.createmarkersopt):
         if ctx.obsolete():
             ui.writenoi18n(b"obsolete\n")
-    ui.write((b"phase %s\n\n" % ctx.phasestr()))
+    ui.writenoi18n(b"phase %s\n\n" % ctx.phasestr())
 
     if prefix != b"":
         ui.write(
--- a/hgext/keyword.py	Tue Jan 07 14:57:51 2025 -0500
+++ b/hgext/keyword.py	Mon Jan 06 13:29:42 2025 -0500
@@ -543,7 +543,7 @@
             if name.split(b'.', 1)[0].find(b'commit') > -1:
                 repo.ui.setconfig(b'hooks', name, b'', b'keyword')
         msg = _(b'hg keyword configuration and expansion example')
-        ui.note((b"hg ci -m '%s'\n" % msg))
+        ui.notenoi18n(b"hg ci -m '%s'\n" % msg)
         repo.commit(text=msg)
     ui.status(_(b'\n\tkeywords expanded\n'))
     ui.write(repo.wread(fn))
--- a/hgext/remotefilelog/debugcommands.py	Tue Jan 07 14:57:51 2025 -0500
+++ b/hgext/remotefilelog/debugcommands.py	Mon Jan 06 13:29:42 2025 -0500
@@ -128,19 +128,15 @@
         basehdr = b'  base'
 
     if format == 0:
-        ui.write(
-            (
-                b"   rev    offset  length " + basehdr + b" linkrev"
-                b" nodeid       p1           p2\n"
-            )
+        ui.writenoi18n(
+            b"   rev    offset  length " + basehdr + b" linkrev"
+            b" nodeid       p1           p2\n"
         )
     elif format == 1:
-        ui.write(
-            (
-                b"   rev flag   offset   length"
-                b"     size " + basehdr + b"   link     p1     p2"
-                b"       nodeid\n"
-            )
+        ui.writenoi18n(
+            b"   rev flag   offset   length"
+            b"     size " + basehdr + b"   link     p1     p2"
+            b"       nodeid\n"
         )
 
     for i in r:
@@ -307,7 +303,7 @@
         for filename, node, deltabase, deltalen in dpack.iterentries():
             bases[node] = deltabase
             if node in nodes:
-                ui.write((b"Bad entry: %s appears twice\n" % short(node)))
+                ui.writenoi18n(b"Bad entry: %s appears twice\n" % short(node))
                 failures += 1
             nodes.add(node)
             if filename != lastfilename:
@@ -350,7 +346,7 @@
 
         failures += _sanitycheck(ui, set(nodes), bases)
         if failures > 1:
-            ui.warn((b"%d failures\n" % failures))
+            ui.warnnoi18n(b"%d failures\n" % failures)
             return 1
 
 
@@ -370,21 +366,17 @@
 
         while deltabase != sha1nodeconstants.nullid:
             if deltabase not in nodes:
-                ui.warn(
-                    (
-                        b"Bad entry: %s has an unknown deltabase (%s)\n"
-                        % (short(node), short(deltabase))
-                    )
+                ui.warnnoi18n(
+                    b"Bad entry: %s has an unknown deltabase (%s)\n"
+                    % (short(node), short(deltabase))
                 )
                 failures += 1
                 break
 
             if deltabase in seen:
-                ui.warn(
-                    (
-                        b"Bad entry: %s has a cycle (at %s)\n"
-                        % (short(node), short(deltabase))
-                    )
+                ui.warnnoi18n(
+                    b"Bad entry: %s has a cycle (at %s)\n"
+                    % (short(node), short(deltabase))
                 )
                 failures += 1
                 break
--- a/hgext/sparse.py	Tue Jan 07 14:57:51 2025 -0500
+++ b/hgext/sparse.py	Mon Jan 06 13:29:42 2025 -0500
@@ -342,7 +342,7 @@
                 ui.status(
                     _(b"Temporarily Included Files (for merge/rebase):\n")
                 )
-                ui.status((b"\n".join(temporaryincludes) + b"\n"))
+                ui.statusnoi18n(b"\n".join(temporaryincludes) + b"\n")
             return
         else:
             raise error.Abort(
--- a/mercurial/debugcommands.py	Tue Jan 07 14:57:51 2025 -0500
+++ b/mercurial/debugcommands.py	Mon Jan 06 13:29:42 2025 -0500
@@ -264,7 +264,7 @@
         progress.update(id)
         for type, data in dagparser.parsedag(text):
             if type == b'n':
-                ui.note((b'node %s\n' % pycompat.bytestr(data)))
+                ui.notenoi18n(b'node %s\n' % pycompat.bytestr(data))
                 id, ps = data
 
                 files = []
@@ -345,10 +345,10 @@
                 at = id
             elif type == b'l':
                 id, name = data
-                ui.note((b'tag %s\n' % name))
+                ui.notenoi18n(b'tag %s\n' % name)
                 tags.append(b"%s %s\n" % (hex(repo.changelog.node(id)), name))
             elif type == b'a':
-                ui.note((b'branch %s\n' % data))
+                ui.notenoi18n(b'branch %s\n' % data)
                 atbranch = data
             progress.update(id)
 
@@ -442,13 +442,15 @@
     """lists the contents of a bundle2"""
     if not isinstance(gen, bundle2.unbundle20):
         raise error.Abort(_(b'not a bundle2 file'))
-    ui.write((b'Stream params: %s\n' % _quasirepr(gen.params)))
+    ui.writenoi18n(b'Stream params: %s\n' % _quasirepr(gen.params))
     parttypes = opts.get('part_type', [])
     for part in gen.iterparts():
         if parttypes and part.type not in parttypes:
             continue
         msg = b'%s -- %s (mandatory: %r)\n'
-        ui.write((msg % (part.type, _quasirepr(part.params), part.mandatory)))
+        ui.writenoi18n(
+            msg % (part.type, _quasirepr(part.params), part.mandatory)
+        )
         if part.type == b'changegroup':
             version = part.params.get(b'version', b'01')
             cg = changegroup.getunbundler(version, part, b'UN')
--- a/mercurial/revlogutils/debug.py	Tue Jan 07 14:57:51 2025 -0500
+++ b/mercurial/revlogutils/debug.py	Mon Jan 06 13:29:42 2025 -0500
@@ -231,11 +231,9 @@
     # XXX seems redundant with debug index ?
     r = revlog
     numrevs = len(r)
-    ui.write(
-        (
-            b"# rev p1rev p2rev start   end deltastart base   p1   p2"
-            b" rawsize totalsize compression heads chainlen\n"
-        )
+    ui.writenoi18n(
+        b"# rev p1rev p2rev start   end deltastart base   p1   p2"
+        b" rawsize totalsize compression heads chainlen\n"
     )
     ts = 0
     heads = set()
--- a/mercurial/upgrade.py	Tue Jan 07 14:57:51 2025 -0500
+++ b/mercurial/upgrade.py	Mon Jan 06 13:29:42 2025 -0500
@@ -170,9 +170,9 @@
                     msg_issued = 1
             touched_revlogs.add(CL)
     if msg_issued >= 2:
-        ui.warn((b"\n"))
+        ui.warnnoi18n(b"\n")
     elif msg_issued >= 1:
-        ui.status((b"\n"))
+        ui.statusnoi18n(b"\n")
 
     upgrade_op = upgrade_actions.UpgradeOperation(
         ui,
--- a/mercurial/upgrade_utils/actions.py	Tue Jan 07 14:57:51 2025 -0500
+++ b/mercurial/upgrade_utils/actions.py	Mon Jan 06 13:29:42 2025 -0500
@@ -882,19 +882,19 @@
         self._write_labeled(
             self._preserved_requirements, b"upgrade-repo.requirement.preserved"
         )
-        self.ui.write((b'\n'))
+        self.ui.writenoi18n(b'\n')
         if self._removed_requirements:
             self.ui.write(_(b'   removed: '))
             self._write_labeled(
                 self._removed_requirements, b"upgrade-repo.requirement.removed"
             )
-            self.ui.write((b'\n'))
+            self.ui.writenoi18n(b'\n')
         if self._added_requirements:
             self.ui.write(_(b'   added: '))
             self._write_labeled(
                 self._added_requirements, b"upgrade-repo.requirement.added"
             )
-            self.ui.write((b'\n'))
+            self.ui.writenoi18n(b'\n')
         self.ui.write(b'\n')
 
     def print_optimisations(self):
@@ -916,12 +916,12 @@
 
     def print_affected_revlogs(self):
         if not self.revlogs_to_process:
-            self.ui.write((b'no revlogs to process\n'))
+            self.ui.writenoi18n(b'no revlogs to process\n')
         else:
-            self.ui.write((b'processed revlogs:\n'))
+            self.ui.writenoi18n(b'processed revlogs:\n')
             for r in sorted(self.revlogs_to_process):
-                self.ui.write((b'  - %s\n' % r))
-        self.ui.write((b'\n'))
+                self.ui.writenoi18n(b'  - %s\n' % r)
+        self.ui.writenoi18n(b'\n')
 
     def print_unused_optimizations(self):
         for i in self.unused_optimizations:
--- a/tests/autodiff.py	Tue Jan 07 14:57:51 2025 -0500
+++ b/tests/autodiff.py	Mon Jan 06 13:29:42 2025 -0500
@@ -62,4 +62,4 @@
     for chunk in it:
         ui.write(chunk)
     for fn in sorted(brokenfiles):
-        ui.write((b'data lost for: %s\n' % fn))
+        ui.writenoi18n(b'data lost for: %s\n' % fn)
--- a/tests/testlib/ext-phase-report.py	Tue Jan 07 14:57:51 2025 -0500
+++ b/tests/testlib/ext-phase-report.py	Mon Jan 06 13:29:42 2025 -0500
@@ -6,18 +6,14 @@
         for revs, move in sorted(tr.changes[b"phases"], key=lambda r: r[0][0]):
             for rev in revs:
                 if move[0] is None:
-                    ui.write(
-                        (
-                            b'test-debug-phase: new rev %d:  x -> %d\n'
-                            % (rev, move[1])
-                        )
+                    ui.writenoi18n(
+                        b'test-debug-phase: new rev %d:  x -> %d\n'
+                        % (rev, move[1])
                     )
                 else:
-                    ui.write(
-                        (
-                            b'test-debug-phase: move rev %d: %d -> %d\n'
-                            % (rev, move[0], move[1])
-                        )
+                    ui.writenoi18n(
+                        b'test-debug-phase: move rev %d: %d -> %d\n'
+                        % (rev, move[0], move[1])
                     )
 
     class reportphaserepo(repo.__class__):