win32mbcs: use str for encoding value stable
authorMatt Harbison <matt_harbison@yahoo.com>
Thu, 11 Jul 2024 11:10:40 -0400
branchstable
changeset 51664 e6508d1e0b47
parent 51663 45ba8416afc4
child 51665 63ede7a43a37
win32mbcs: use str for encoding value This was reported to the TortoiseHg tracker as: https://foss.heptapod.net/mercurial/tortoisehg/thg/-/issues/5980 It doesn't look like we have any tests for this extension, but the explicit type hints are enough to convince pytype that the module level `_encoding` attr is str. The `encode()` and `decode()` methods are too complex to add type hints for them.
hgext/win32mbcs.py
--- a/hgext/win32mbcs.py	Fri Jul 12 15:29:35 2024 +0400
+++ b/hgext/win32mbcs.py	Thu Jul 11 11:10:40 2024 -0400
@@ -73,7 +73,7 @@
     default=lambda: encoding.encoding,
 )
 
-_encoding = None  # see extsetup
+_encoding: str = ""  # see extsetup
 
 
 def decode(arg):
@@ -129,7 +129,7 @@
     except UnicodeError:
         raise error.Abort(
             _(b"[win32mbcs] filename conversion failed with %s encoding\n")
-            % _encoding
+            % encoding.strtolocal(_encoding)
         )
 
 
@@ -199,7 +199,7 @@
         return
     # determine encoding for filename
     global _encoding
-    _encoding = ui.config(b'win32mbcs', b'encoding')
+    _encoding = encoding.strfromlocal(ui.config(b'win32mbcs', b'encoding'))
     # fake is only for relevant environment.
     if _encoding.lower() in problematic_encodings.split():
         for f in funcs.split():
@@ -217,5 +217,6 @@
         # extensions.loadall() is called.
         if '--debug' in sys.argv:
             ui.writenoi18n(
-                b"[win32mbcs] activated with encoding: %s\n" % _encoding
+                b"[win32mbcs] activated with encoding: %s\n"
+                % encoding.strtolocal(_encoding)
             )