unionrepo: fix mismatches with revlog classes
authorMatt Harbison <matt_harbison@yahoo.com>
Thu, 19 Sep 2024 18:48:07 -0400
changeset 51875 8315175f678d
parent 51874 1b17309cdaab
child 51876 51235f6aa067
unionrepo: fix mismatches with revlog classes This is a subset of cfd30df0f8e4, applied to `unionrepository`. There are none of the `write()` method overrides here, like `bundlerepository`. With these changes, pytype flags the `unionrevlog` constructor: File "/mnt/c/Users/Matt/hg/mercurial/unionrepo.py", line 55, in __init__: No attribute '_revlog' on mercurial.changelog.changelog [attribute-error] Called from (traceback): line 207, in __init__ File "/mnt/c/Users/Matt/hg/mercurial/unionrepo.py", line 55, in __init__: No attribute '_revlog' on mercurial.revlog.revlog [attribute-error] Called from (traceback): line 232, in __init__ But it turns out that both `changelog.changelog` and `revlog.revlog` do have a `target` attribute, so they wouldn't trip over this. It seems weird that the second caller to be flagged is passing the private `_revlog`, but maybe that's how it needs to be.
mercurial/unionrepo.py
--- a/mercurial/unionrepo.py	Thu Sep 19 16:19:29 2024 -0400
+++ b/mercurial/unionrepo.py	Thu Sep 19 18:48:07 2024 -0400
@@ -39,7 +39,9 @@
 
 
 class unionrevlog(revlog.revlog):
-    def __init__(self, opener, radix, revlog2, linkmapper):
+    def __init__(self, opener: typing.Any, radix, revlog2, linkmapper):
+        # TODO: figure out real type of opener
+        #
         # How it works:
         # To retrieve a revision, we just need to know the node id so we can
         # look it up in revlog2.
@@ -49,6 +51,10 @@
         opener = vfsmod.readonlyvfs(opener)
         target = getattr(revlog2, 'target', None)
         if target is None:
+            # Help pytype- changelog and revlog are not possible here because
+            # they both have a 'target' attr.
+            assert not isinstance(revlog2, (changelog.changelog, revlog.revlog))
+
             # a revlog wrapper, eg: the manifestlog that is not an actual revlog
             target = revlog2._revlog.target
         revlog.revlog.__init__(self, opener, target=target, radix=radix)
@@ -131,7 +137,7 @@
 
     def _chunk(self, rev):
         if rev <= self.repotiprev:
-            return revlog.revlog._chunk(self, rev)
+            return super(unionrevlog, self)._inner._chunk(rev)
         return self.revlog2._chunk(self.node(rev))
 
     def revdiff(self, rev1, rev2):