changeset 51820:71fb6e0a7a35

typing: add type hints to the `opener` attributes and arguments of revlog When making revlog and filelog classes visible to pytype, it got confused quite a bit in `mercurial/revlogutils/rewrite.py`, thinking it had a plain `Callable`, and flagging additional methods on it like `join()` and `rename()`. I couldn't figure out how it reduced to that (and PyCharm flagged `opener` references as `Any`), but this makes it happy. So make this change before making the classes visible. The vfs class hierarchy is a bit wonky (e.g. `filteredvfs` is not a `vfs`), so this may need to be revisited with a Protocol class that covers all of the `vfs` classes. But for now, everything works.
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 21 Aug 2024 16:13:14 -0400
parents 438f4fca513e
children c371134fef01
files mercurial/revlog.py
diffstat 1 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Wed Aug 21 16:09:22 2024 -0400
+++ b/mercurial/revlog.py	Wed Aug 21 16:13:14 2024 -0400
@@ -91,6 +91,7 @@
     revlogutils,
     templatefilters,
     util,
+    vfs as vfsmod,
 )
 from .interfaces import (
     repository,
@@ -363,9 +364,11 @@
     boundaries are arbitrary and based on what we can delegate to Rust.
     """
 
+    opener: vfsmod.vfs
+
     def __init__(
         self,
-        opener,
+        opener: vfsmod.vfs,
         index,
         index_file,
         data_file,
@@ -1293,6 +1296,8 @@
 
     _flagserrorclass = error.RevlogError
 
+    opener: vfsmod.vfs
+
     @staticmethod
     def is_inline_index(header_bytes):
         """Determine if a revlog is inline from the initial bytes of the index"""
@@ -1311,7 +1316,7 @@
 
     def __init__(
         self,
-        opener,
+        opener: vfsmod.vfs,
         target,
         radix,
         postfix=None,  # only exist for `tmpcensored` now