changeset 51859:b60f25f00e94

typing: add explicit hints for recent pytype regressions Somewhere between 454feddab720 and cd72a88c5599, pytype changed how it inferred the return type in `extdiff.py` from Tuple[Any, List[Tuple[bytes, Any, os.stat_result]]] to Tuple[Any, List[nothing]] It also changed the return type in `archival.py` from `Any` to `NoReturn`. Fix those up, and also the obvious parameter types while we're here.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 12 Sep 2024 12:28:27 -0400
parents 2fd44b3dcc33
children 8c39ba94acce
files hgext/extdiff.py mercurial/archival.py
diffstat 2 files changed, 38 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/extdiff.py	Wed Jun 19 18:06:50 2024 +0200
+++ b/hgext/extdiff.py	Thu Sep 12 12:28:27 2024 -0400
@@ -87,6 +87,12 @@
 import shutil
 import stat
 import subprocess
+import typing
+from typing import (
+    List,
+    Optional,
+    Tuple,
+)
 
 from mercurial.i18n import _
 from mercurial.node import (
@@ -111,6 +117,12 @@
     stringutil,
 )
 
+if typing.TYPE_CHECKING:
+    from mercurial import (
+        localrepo,
+        ui as uimod,
+    )
+
 cmdtable = {}
 command = registrar.command(cmdtable)
 
@@ -150,7 +162,14 @@
 testedwith = b'ships-with-hg-core'
 
 
-def snapshot(ui, repo, files, node, tmproot, listsubrepos):
+def snapshot(
+    ui: "uimod.ui",
+    repo: "localrepo.localrepository",
+    files,
+    node: Optional[bytes],
+    tmproot: bytes,
+    listsubrepos: bool,
+) -> Tuple[bytes, List[Tuple[bytes, bytes, os.stat_result]]]:
     """snapshot files as of some revision
     if not using snapshot, -I/-X does not work and recursive diff
     in tools like kdiff3 and meld displays too many files."""
--- a/mercurial/archival.py	Wed Jun 19 18:06:50 2024 +0200
+++ b/mercurial/archival.py	Thu Sep 12 12:28:27 2024 -0400
@@ -11,9 +11,14 @@
 import struct
 import tarfile
 import time
+import typing
 import zipfile
 import zlib
 
+from typing import (
+    Optional,
+)
+
 from .i18n import _
 from .node import nullrev
 from .pycompat import open
@@ -30,6 +35,11 @@
 
 from .utils import stringutil
 
+if typing.TYPE_CHECKING:
+    from . import (
+        localrepo,
+    )
+
 stringio = util.stringio
 
 # from unzip source code:
@@ -281,16 +291,16 @@
 
 
 def archive(
-    repo,
-    dest,
+    repo: "localrepo.localrepository",
+    dest,  # TODO: should be bytes, but could be Callable
     node,
-    kind,
-    decode=True,
+    kind: bytes,
+    decode: bool = True,
     match=None,
-    prefix=b'',
-    mtime=None,
-    subrepos=False,
-):
+    prefix: bytes = b'',
+    mtime: Optional[float] = None,
+    subrepos: bool = False,
+) -> int:
     """create archive of repo as it was at node.
 
     dest can be name of directory, name of archive file, a callable, or file