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.
--- 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