diff mercurial/manifest.py @ 51822:0338fb200a30

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.)
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 21 Aug 2024 22:15:05 -0400
parents 5eb98ea78fd7
children f4733654f144
line wrap: on
line diff
--- 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