# HG changeset patch # User Matt Harbison # Date 1724292905 14400 # Node ID 0338fb200a308bb6c44136a7ee2b3307d7b04637 # Parent 766c554922585148f21174aeb8a793f472023951 typing: lock in new pytype gains from making revlog related classes typeable These were pretty clean changes in the pyi files from earlier in this series, so add them to the code to make it more understandable. There's one more trivial hint that can be added to the return of `mercurial.revlogutils.rewrite._filelog_from_filename()`, however it needs to be imported from '..' under the conditional of `typing.TYPE_CHECKING`, and that seems to confuse the import checker- possibly because there's already an import block from that level. (I would have expected a message about multiple import statements in this case, but got one about higher level imports should come first, no matter where I put the import statement.) diff -r 766c55492258 -r 0338fb200a30 hgext/remotefilelog/debugcommands.py --- a/hgext/remotefilelog/debugcommands.py Tue Aug 20 00:07:05 2024 -0400 +++ b/hgext/remotefilelog/debugcommands.py Wed Aug 21 22:15:05 2024 -0400 @@ -62,7 +62,7 @@ queue.append(p2) -def buildtemprevlog(repo, file): +def buildtemprevlog(repo, file) -> filelog.FileLog: # get filename key filekey = hex(hashutil.sha1(file).digest()) filedir = os.path.join(repo.path, b'store/data', filekey) diff -r 766c55492258 -r 0338fb200a30 hgext/remotefilelog/remotefilelog.py --- a/hgext/remotefilelog/remotefilelog.py Tue Aug 20 00:07:05 2024 -0400 +++ b/hgext/remotefilelog/remotefilelog.py Wed Aug 21 22:15:05 2024 -0400 @@ -8,6 +8,10 @@ import collections +from typing import ( + Iterator, +) + from mercurial.node import bin from mercurial.i18n import _ from mercurial import ( @@ -296,7 +300,7 @@ deltamode=None, sidedata_helpers=None, debug_info=None, - ): + ) -> Iterator[revlog.RevLogRevisionDelta]: # we don't use any of these parameters here del nodesorder, revisiondata, assumehaveparentrevisions, deltaprevious del deltamode diff -r 766c55492258 -r 0338fb200a30 mercurial/filelog.py --- a/mercurial/filelog.py Tue Aug 20 00:07:05 2024 -0400 +++ b/mercurial/filelog.py Wed Aug 21 22:15:05 2024 -0400 @@ -8,6 +8,11 @@ import typing +from typing import ( + Iterable, + Iterator, +) + from .i18n import _ from .node import nullrev from . import ( @@ -26,6 +31,10 @@ class FileLog: + _revlog: revlog.revlog + nullid: bytes + _fix_issue6528: bool + def __init__(self, opener, path, try_split=False): self._revlog = revlog.revlog( opener, @@ -43,7 +52,7 @@ opts = opener.options self._fix_issue6528 = opts.get(b'issue6528.fix-incoming', True) - def get_revlog(self): + def get_revlog(self) -> revlog.revlog: """return an actual revlog instance if any This exist because a lot of code leverage the fact the underlying @@ -52,10 +61,10 @@ """ return self._revlog - def __len__(self): + def __len__(self) -> int: return len(self._revlog) - def __iter__(self): + def __iter__(self) -> Iterator[int]: return self._revlog.__iter__() def hasnode(self, node): @@ -234,7 +243,7 @@ """ return not storageutil.filedataequivalent(self, node, text) - def verifyintegrity(self, state): + def verifyintegrity(self, state) -> Iterable[revlog.RevLogProblem]: return self._revlog.verifyintegrity(state) def storageinfo( diff -r 766c55492258 -r 0338fb200a30 mercurial/manifest.py --- a/mercurial/manifest.py Tue Aug 20 00:07:05 2024 -0400 +++ b/mercurial/manifest.py Wed Aug 21 22:15:05 2024 -0400 @@ -850,6 +850,12 @@ class TreeManifest: + _dir: bytes + _dirs: Dict[bytes, 'TreeManifest'] + _dirty: bool + _files: Dict[bytes, bytes] + _flags: Dict[bytes, bytes] + def __init__(self, nodeconstants, dir: bytes = b'', text: bytes = b''): self._dir = dir self.nodeconstants = nodeconstants @@ -858,13 +864,13 @@ self._loadfunc = _noop self._copyfunc = _noop self._dirty = False - self._dirs: Dict[bytes, 'TreeManifest'] = {} + self._dirs = {} self._lazydirs: Dict[ bytes, Tuple[bytes, Callable[[bytes, bytes], 'TreeManifest'], bool], ] = {} # Using _lazymanifest here is a little slower than plain old dicts - self._files: Dict[bytes, bytes] = {} + self._files = {} self._flags = {} if text: @@ -2172,6 +2178,8 @@ class MemManifestCtx: + _manifestdict: ManifestDict + def __init__(self, manifestlog): self._manifestlog = manifestlog self._manifestdict = manifestdict(manifestlog.nodeconstants.nodelen) @@ -2213,6 +2221,8 @@ contents, its parent revs, and its linkrev. """ + _data: Optional[ManifestDict] + def __init__(self, manifestlog, node): self._manifestlog = manifestlog self._data = None @@ -2375,6 +2385,8 @@ class MemTreeManifestCtx: + _treemanifest: TreeManifest + def __init__(self, manifestlog, dir=b''): self._manifestlog = manifestlog self._dir = dir @@ -2417,6 +2429,8 @@ class TreeManifestCtx: + _data: Optional[TreeManifest] + def __init__(self, manifestlog, dir, node): self._manifestlog = manifestlog self._dir = dir @@ -2699,6 +2713,9 @@ whose contents are unknown. """ + _files: Dict[bytes, bytes] + _flags: Dict[bytes, bytes] + def __init__(self, nodeconstants, dir, node): super(excludeddir, self).__init__(nodeconstants, dir) self._node = node diff -r 766c55492258 -r 0338fb200a30 mercurial/revlog.py --- a/mercurial/revlog.py Tue Aug 20 00:07:05 2024 -0400 +++ b/mercurial/revlog.py Wed Aug 21 22:15:05 2024 -0400 @@ -25,6 +25,8 @@ import zlib from typing import ( + Iterable, + Iterator, Optional, Tuple, ) @@ -1826,7 +1828,7 @@ def __len__(self): return len(self.index) - def __iter__(self): + def __iter__(self) -> Iterator[int]: return iter(range(len(self))) def revs(self, start=0, stop=None): @@ -3902,7 +3904,7 @@ else: rewrite.v2_censor(self, tr, censor_nodes, tombstone) - def verifyintegrity(self, state): + def verifyintegrity(self, state) -> Iterable[RevLogProblem]: """Verifies the integrity of the revlog. Yields ``revlogproblem`` instances describing problems that are diff -r 766c55492258 -r 0338fb200a30 mercurial/statichttprepo.py --- a/mercurial/statichttprepo.py Tue Aug 20 00:07:05 2024 -0400 +++ b/mercurial/statichttprepo.py Wed Aug 21 22:15:05 2024 -0400 @@ -160,6 +160,8 @@ ): supported = localrepo.localrepository._basesupported + manifestlog: manifest.ManifestLog + def __init__(self, ui, path): self._url = path self.ui = ui diff -r 766c55492258 -r 0338fb200a30 mercurial/store.py --- a/mercurial/store.py Tue Aug 20 00:07:05 2024 -0400 +++ b/mercurial/store.py Wed Aug 21 22:15:05 2024 -0400 @@ -817,7 +817,7 @@ concurrencychecker=concurrencychecker, ) - def manifestlog(self, repo, storenarrowmatch): + def manifestlog(self, repo, storenarrowmatch) -> manifest.ManifestLog: rootstore = manifest.manifestrevlog(repo.nodeconstants, self.vfs) return manifest.manifestlog(self.vfs, repo, rootstore, storenarrowmatch) diff -r 766c55492258 -r 0338fb200a30 mercurial/unionrepo.py --- a/mercurial/unionrepo.py Tue Aug 20 00:07:05 2024 -0400 +++ b/mercurial/unionrepo.py Wed Aug 21 22:15:05 2024 -0400 @@ -204,6 +204,9 @@ class unionmanifest(unionrevlog, manifest.manifestrevlog): + repotiprev: int + revlog2: manifest.ManifestRevlog + def __init__(self, nodeconstants, opener, opener2, linkmapper): # XXX manifestrevlog is not actually a revlog , so mixing it with # bundlerevlog is not a good idea. @@ -215,6 +218,10 @@ class unionfilelog(filelog.filelog): + _revlog: unionrevlog + repotiprev: int + revlog2: revlog.revlog + def __init__(self, opener, path, opener2, linkmapper, repo): filelog.filelog.__init__(self, opener, path) filelog2 = filelog.filelog(opener2, path)