Mercurial > public > mercurial-scm > hg
comparison hgext/git/manifest.py @ 52491:c855943e334b
git: fix `repository.imanifestdict` implementation flaws detected by pytype
The next logical step is to align the signatures on `repository.imanifestdict`
and the logical subclasses. But that requires this small detour, as doing that
caused these errors:
File "/mnt/c/Users/Matt/hg/hgext/git/manifest.py", line 247, in items:
bad return type [bad-return-type]
Expected: Tuple[bytes, bytes]
Actually returned: bytes
File "/mnt/c/Users/Matt/hg/hgext/git/manifest.py", line 255, in iterentries:
bad return type [bad-return-type]
Expected: Tuple[bytes, bytes, bytes]
Actually returned: Tuple[Any, bytes]
The type annotation added to `_resolve_entry()` here to help clarify things then
caused PyCharm to flag `gittreemanifestctx.find()` for a bad return type, also
fixed here.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 24 Oct 2024 22:24:46 -0400 |
parents | 22f97aa5e8b2 |
children | 48cdbd4d5443 |
comparison
equal
deleted
inserted
replaced
52490:ef119f914fc1 | 52491:c855943e334b |
---|---|
40 if pending_changes is None: | 40 if pending_changes is None: |
41 pending_changes = {} | 41 pending_changes = {} |
42 # dict of path: Optional[Tuple(node, flags)] | 42 # dict of path: Optional[Tuple(node, flags)] |
43 self._pending_changes = pending_changes | 43 self._pending_changes = pending_changes |
44 | 44 |
45 def _resolve_entry(self, path): | 45 def _resolve_entry(self, path) -> tuple[bytes, bytes]: |
46 """Given a path, load its node and flags, or raise KeyError if missing. | 46 """Given a path, load its node and flags, or raise KeyError if missing. |
47 | 47 |
48 This takes into account any pending writes in the builder. | 48 This takes into account any pending writes in the builder. |
49 """ | 49 """ |
50 upath = pycompat.fsdecode(path) | 50 upath = pycompat.fsdecode(path) |
222 ) | 222 ) |
223 | 223 |
224 def items(self): | 224 def items(self): |
225 for f in self: | 225 for f in self: |
226 # TODO: build a proper iterator version of this | 226 # TODO: build a proper iterator version of this |
227 yield self[f] | 227 yield f, self[f] |
228 | 228 |
229 def iteritems(self): | 229 def iteritems(self): |
230 return self.items() | 230 return self.items() |
231 | 231 |
232 def iterentries(self): | 232 def iterentries(self): |
233 for f in self: | 233 for f in self: |
234 # TODO: build a proper iterator version of this | 234 # TODO: build a proper iterator version of this |
235 yield self._resolve_entry(f) | 235 yield f, *self._resolve_entry(f) |
236 | 236 |
237 def text(self): | 237 def text(self): |
238 assert False # TODO can this method move out of the manifest iface? | 238 assert False # TODO can this method move out of the manifest iface? |
239 | 239 |
240 def _walkonetree(self, tree, match, subdir): | 240 def _walkonetree(self, tree, match, subdir): |
274 # NB: it's important that we return a memgittreemanifestctx | 274 # NB: it's important that we return a memgittreemanifestctx |
275 # because the caller expects a mutable manifest. | 275 # because the caller expects a mutable manifest. |
276 return memgittreemanifestctx(self._repo, self._tree) | 276 return memgittreemanifestctx(self._repo, self._tree) |
277 | 277 |
278 def find(self, path: bytes) -> tuple[bytes, bytes]: | 278 def find(self, path: bytes) -> tuple[bytes, bytes]: |
279 return self.read()[path] | 279 return self.read().find(path) |
280 | 280 |
281 | 281 |
282 class memgittreemanifestctx(repository.imanifestrevisionwritable): | 282 class memgittreemanifestctx(repository.imanifestrevisionwritable): |
283 def __init__(self, repo, tree): | 283 def __init__(self, repo, tree): |
284 self._repo = repo | 284 self._repo = repo |