changeset 51757:a1e4fa9330d8

typing: add type hints around the matcher for subrepo archiving Mostly this is meant to try to smoke out any other potential issues around the matcher, since these args were mostly previously treated as `Any`, and therefore checking wasn't done.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 01 Aug 2024 11:43:10 -0400
parents a53162bd73ed
children 421c9b3f2f4e
files hgext/largefiles/overrides.py mercurial/match.py mercurial/subrepo.py
diffstat 3 files changed, 17 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/largefiles/overrides.py	Thu Aug 01 01:52:11 2024 -0400
+++ b/hgext/largefiles/overrides.py	Thu Aug 01 11:43:10 2024 -0400
@@ -11,6 +11,9 @@
 import contextlib
 import copy
 import os
+from typing import (
+    Optional,
+)
 
 from mercurial.i18n import _
 
@@ -1224,7 +1227,7 @@
     node,
     kind,
     decode=True,
-    match=None,
+    match: Optional[matchmod.basematcher] = None,
     prefix=b'',
     mtime=None,
     subrepos=None,
@@ -1317,7 +1320,9 @@
 
 
 @eh.wrapfunction(subrepo.hgsubrepo, 'archive')
-def hgsubrepoarchive(orig, repo, archiver, prefix, match, decode=True):
+def hgsubrepoarchive(
+    orig, repo, archiver, prefix, match: matchmod.basematcher, decode=True
+):
     lfenabled = hasattr(repo._repo, '_largefilesenabled')
     if not lfenabled or not repo._repo.lfstatus:
         return orig(repo, archiver, prefix, match, decode)
--- a/mercurial/match.py	Thu Aug 01 01:52:11 2024 -0400
+++ b/mercurial/match.py	Thu Aug 01 11:43:10 2024 -0400
@@ -1071,7 +1071,7 @@
     sub/x.txt: No such file
     """
 
-    def __init__(self, path, matcher):
+    def __init__(self, path: bytes, matcher: basematcher) -> None:
         super(subdirmatcher, self).__init__()
         self._path = path
         self._matcher = matcher
--- a/mercurial/subrepo.py	Thu Aug 01 01:52:11 2024 -0400
+++ b/mercurial/subrepo.py	Thu Aug 01 11:43:10 2024 -0400
@@ -363,7 +363,9 @@
         """handle the files command for this subrepo"""
         return 1
 
-    def archive(self, archiver, prefix, match, decode=True):
+    def archive(
+        self, archiver, prefix, match: matchmod.basematcher, decode=True
+    ):
         files = [f for f in self.files() if match(f)]
         total = len(files)
         relpath = subrelpath(self)
@@ -649,7 +651,9 @@
             )
 
     @annotatesubrepoerror
-    def archive(self, archiver, prefix, match, decode=True):
+    def archive(
+        self, archiver, prefix, match: matchmod.basematcher, decode=True
+    ):
         self._get(self._state + (b'hg',))
         files = [f for f in self.files() if match(f)]
         rev = self._state[1]
@@ -1906,7 +1910,9 @@
             else:
                 self.wvfs.unlink(f)
 
-    def archive(self, archiver, prefix, match, decode=True):
+    def archive(
+        self, archiver, prefix, match: matchmod.basematcher, decode=True
+    ):
         total = 0
         source, revision = self._state
         if not revision: