Mercurial > public > mercurial-scm > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
51821:766c55492258 | 51822:0338fb200a30 |
---|---|
848 | 848 |
849 _noop = lambda s: None | 849 _noop = lambda s: None |
850 | 850 |
851 | 851 |
852 class TreeManifest: | 852 class TreeManifest: |
853 _dir: bytes | |
854 _dirs: Dict[bytes, 'TreeManifest'] | |
855 _dirty: bool | |
856 _files: Dict[bytes, bytes] | |
857 _flags: Dict[bytes, bytes] | |
858 | |
853 def __init__(self, nodeconstants, dir: bytes = b'', text: bytes = b''): | 859 def __init__(self, nodeconstants, dir: bytes = b'', text: bytes = b''): |
854 self._dir = dir | 860 self._dir = dir |
855 self.nodeconstants = nodeconstants | 861 self.nodeconstants = nodeconstants |
856 self._node = self.nodeconstants.nullid | 862 self._node = self.nodeconstants.nullid |
857 self._nodelen = self.nodeconstants.nodelen | 863 self._nodelen = self.nodeconstants.nodelen |
858 self._loadfunc = _noop | 864 self._loadfunc = _noop |
859 self._copyfunc = _noop | 865 self._copyfunc = _noop |
860 self._dirty = False | 866 self._dirty = False |
861 self._dirs: Dict[bytes, 'TreeManifest'] = {} | 867 self._dirs = {} |
862 self._lazydirs: Dict[ | 868 self._lazydirs: Dict[ |
863 bytes, | 869 bytes, |
864 Tuple[bytes, Callable[[bytes, bytes], 'TreeManifest'], bool], | 870 Tuple[bytes, Callable[[bytes, bytes], 'TreeManifest'], bool], |
865 ] = {} | 871 ] = {} |
866 # Using _lazymanifest here is a little slower than plain old dicts | 872 # Using _lazymanifest here is a little slower than plain old dicts |
867 self._files: Dict[bytes, bytes] = {} | 873 self._files = {} |
868 self._flags = {} | 874 self._flags = {} |
869 if text: | 875 if text: |
870 | 876 |
871 def readsubtree(subdir, subm): | 877 def readsubtree(subdir, subm): |
872 raise AssertionError( | 878 raise AssertionError( |
2170 if typing.TYPE_CHECKING: | 2176 if typing.TYPE_CHECKING: |
2171 manifestlog = ManifestLog | 2177 manifestlog = ManifestLog |
2172 | 2178 |
2173 | 2179 |
2174 class MemManifestCtx: | 2180 class MemManifestCtx: |
2181 _manifestdict: ManifestDict | |
2182 | |
2175 def __init__(self, manifestlog): | 2183 def __init__(self, manifestlog): |
2176 self._manifestlog = manifestlog | 2184 self._manifestlog = manifestlog |
2177 self._manifestdict = manifestdict(manifestlog.nodeconstants.nodelen) | 2185 self._manifestdict = manifestdict(manifestlog.nodeconstants.nodelen) |
2178 | 2186 |
2179 def _storage(self) -> ManifestRevlog: | 2187 def _storage(self) -> ManifestRevlog: |
2210 | 2218 |
2211 class ManifestCtx: | 2219 class ManifestCtx: |
2212 """A class representing a single revision of a manifest, including its | 2220 """A class representing a single revision of a manifest, including its |
2213 contents, its parent revs, and its linkrev. | 2221 contents, its parent revs, and its linkrev. |
2214 """ | 2222 """ |
2223 | |
2224 _data: Optional[ManifestDict] | |
2215 | 2225 |
2216 def __init__(self, manifestlog, node): | 2226 def __init__(self, manifestlog, node): |
2217 self._manifestlog = manifestlog | 2227 self._manifestlog = manifestlog |
2218 self._data = None | 2228 self._data = None |
2219 | 2229 |
2373 if typing.TYPE_CHECKING: | 2383 if typing.TYPE_CHECKING: |
2374 manifestctx = ManifestCtx | 2384 manifestctx = ManifestCtx |
2375 | 2385 |
2376 | 2386 |
2377 class MemTreeManifestCtx: | 2387 class MemTreeManifestCtx: |
2388 _treemanifest: TreeManifest | |
2389 | |
2378 def __init__(self, manifestlog, dir=b''): | 2390 def __init__(self, manifestlog, dir=b''): |
2379 self._manifestlog = manifestlog | 2391 self._manifestlog = manifestlog |
2380 self._dir = dir | 2392 self._dir = dir |
2381 self._treemanifest = treemanifest(manifestlog.nodeconstants) | 2393 self._treemanifest = treemanifest(manifestlog.nodeconstants) |
2382 | 2394 |
2415 if typing.TYPE_CHECKING: | 2427 if typing.TYPE_CHECKING: |
2416 memtreemanifestctx = MemTreeManifestCtx | 2428 memtreemanifestctx = MemTreeManifestCtx |
2417 | 2429 |
2418 | 2430 |
2419 class TreeManifestCtx: | 2431 class TreeManifestCtx: |
2432 _data: Optional[TreeManifest] | |
2433 | |
2420 def __init__(self, manifestlog, dir, node): | 2434 def __init__(self, manifestlog, dir, node): |
2421 self._manifestlog = manifestlog | 2435 self._manifestlog = manifestlog |
2422 self._dir = dir | 2436 self._dir = dir |
2423 self._data = None | 2437 self._data = None |
2424 | 2438 |
2697 detect a merge conflict outside the narrowspec. That's what this | 2711 detect a merge conflict outside the narrowspec. That's what this |
2698 class is: it stands in for a directory whose node is known, but | 2712 class is: it stands in for a directory whose node is known, but |
2699 whose contents are unknown. | 2713 whose contents are unknown. |
2700 """ | 2714 """ |
2701 | 2715 |
2716 _files: Dict[bytes, bytes] | |
2717 _flags: Dict[bytes, bytes] | |
2718 | |
2702 def __init__(self, nodeconstants, dir, node): | 2719 def __init__(self, nodeconstants, dir, node): |
2703 super(excludeddir, self).__init__(nodeconstants, dir) | 2720 super(excludeddir, self).__init__(nodeconstants, dir) |
2704 self._node = node | 2721 self._node = node |
2705 # Add an empty file, which will be included by iterators and such, | 2722 # Add an empty file, which will be included by iterators and such, |
2706 # appearing as the directory itself (i.e. something like "dir/") | 2723 # appearing as the directory itself (i.e. something like "dir/") |