comparison mercurial/subrepo.py @ 52481:9d79ffeed7c0

typing: use the `Status` protocol wherever `scmutil.status` was being used This likely isn't everything, but these were all of the places the latter was referenced in the generated *.pyi files, plus a few cases that were inferred as `Any`, but found in a module that was being changed anyway. We should figure out some sort of consistency as far as naming these Protocol classes (stdlib ones tend to be CamelCase and imported directly). The current convention of `from xxx.interfaces import foo as ifoo` is a little clever, but a little annoying to type out. Also, this package is likely to grow beyond just Protocol classes, where treating the types as interfaces is wrong (e.g. a theoretical `NodeT` type to represent the binary form of a node, instead of treating that and the incompatible hex form as both bytes). But that's a project for another day.
author Matt Harbison <matt_harbison@yahoo.com>
date Mon, 09 Dec 2024 00:21:38 -0500
parents f4733654f144
children 35cc15fbc523
comparison
equal deleted inserted replaced
52480:f5d134e57f51 52481:9d79ffeed7c0
37 scmutil, 37 scmutil,
38 subrepoutil, 38 subrepoutil,
39 util, 39 util,
40 vfs as vfsmod, 40 vfs as vfsmod,
41 ) 41 )
42 from .interfaces import (
43 status as istatus,
44 )
42 from .utils import ( 45 from .utils import (
43 dateutil, 46 dateutil,
44 hashutil, 47 hashutil,
45 procutil, 48 procutil,
46 urlutil, 49 urlutil,
330 return 1 333 return 1
331 334
332 def cat(self, match, fm, fntemplate, prefix, **opts): 335 def cat(self, match, fm, fntemplate, prefix, **opts):
333 return 1 336 return 1
334 337
335 def status(self, rev2, **opts): 338 def status(self, rev2, **opts) -> istatus.Status:
336 return scmutil.status([], [], [], [], [], [], []) 339 return scmutil.status([], [], [], [], [], [], [])
337 340
338 def diff(self, ui, diffopts, node2, match, prefix, **opts): 341 def diff(self, ui, diffopts, node2, match, prefix, **opts):
339 pass 342 pass
340 343
612 return cmdutil.cat( 615 return cmdutil.cat(
613 self.ui, self._repo, ctx, match, fm, fntemplate, prefix, **opts 616 self.ui, self._repo, ctx, match, fm, fntemplate, prefix, **opts
614 ) 617 )
615 618
616 @annotatesubrepoerror 619 @annotatesubrepoerror
617 def status(self, rev2, **opts): 620 def status(self, rev2, **opts) -> istatus.Status:
618 try: 621 try:
619 rev1 = self._state[1] 622 rev1 = self._state[1]
620 ctx1 = self._repo[rev1] 623 ctx1 = self._repo[rev1]
621 ctx2 = self._repo[rev2] 624 ctx2 = self._repo[rev2]
622 return self._repo.status(ctx1, ctx2, **opts) 625 return self._repo.status(ctx1, ctx2, **opts)
1969 fp.write(output) 1972 fp.write(output)
1970 fp.close() 1973 fp.close()
1971 return 0 1974 return 0
1972 1975
1973 @annotatesubrepoerror 1976 @annotatesubrepoerror
1974 def status(self, rev2, **opts): 1977 def status(self, rev2, **opts) -> istatus.Status:
1975 rev1 = self._state[1] 1978 rev1 = self._state[1]
1976 if self._gitmissing() or not rev1: 1979 if self._gitmissing() or not rev1:
1977 # if the repo is missing, return no results 1980 # if the repo is missing, return no results
1978 return scmutil.status([], [], [], [], [], [], []) 1981 return scmutil.status([], [], [], [], [], [], [])
1979 modified, added, removed = [], [], [] 1982 modified, added, removed = [], [], []