mercurial/cmdutil.py
changeset 52604 89215c5b714c
parent 52452 9d79ffeed7c0
child 52640 24ee91ba9aa8
--- a/mercurial/cmdutil.py	Tue Dec 31 22:36:56 2024 -0500
+++ b/mercurial/cmdutil.py	Mon Dec 16 21:50:24 2024 -0500
@@ -17,8 +17,10 @@
 from typing import (
     Any,
     AnyStr,
+    BinaryIO,
     Dict,
     Iterable,
+    Literal,
     Optional,
     TYPE_CHECKING,
     cast,
@@ -1360,7 +1362,7 @@
     return b''.join(newname)
 
 
-def makefilename(ctx, pat, **props):
+def makefilename(ctx, pat: bytes, **props):
     if not pat:
         return pat
     tmpl = _buildfntemplate(pat, **props)
@@ -1376,7 +1378,7 @@
 
 
 class _unclosablefile:
-    def __init__(self, fp):
+    def __init__(self, fp: BinaryIO) -> None:
         self._fp = fp
 
     def close(self):
@@ -1395,8 +1397,10 @@
         pass
 
 
-def makefileobj(ctx, pat, mode=b'wb', **props):
-    writable = mode not in (b'r', b'rb')
+def makefileobj(
+    ctx, pat: bytes, mode: Literal['rb', 'wb'] = 'wb', **props
+) -> BinaryIO:
+    writable = mode not in ('r', 'rb')
 
     if isstdiofilename(pat):
         repo = ctx.repo()
@@ -1404,9 +1408,9 @@
             fp = repo.ui.fout
         else:
             fp = repo.ui.fin
-        return _unclosablefile(fp)
+        return typing.cast(BinaryIO, _unclosablefile(fp))
     fn = makefilename(ctx, pat, **props)
-    return open(fn, pycompat.sysstr(mode))
+    return open(fn, mode)
 
 
 def openstorage(repo, cmd, file_, opts, returnrevlog=False):