Mercurial > public > mercurial-scm > hg
changeset 52452: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 | f5d134e57f51 |
children | 1a72e270f3b2 |
files | mercurial/cmdutil.py mercurial/context.py mercurial/interfaces/dirstate.py mercurial/subrepo.py mercurial/subrepoutil.py |
diffstat | 5 files changed, 29 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Mon Dec 09 00:01:03 2024 -0500 +++ b/mercurial/cmdutil.py Mon Dec 09 00:21:38 2024 -0500 @@ -81,6 +81,9 @@ ) if TYPE_CHECKING: + from .interfaces import ( + status as istatus, + ) from . import ( ui as uimod, ) @@ -796,7 +799,7 @@ yield st, fpath -def tersedir(statuslist, terseargs): +def tersedir(statuslist: istatus.Status, terseargs) -> istatus.Status: """ Terse the status if all the files in a directory shares the same status.
--- a/mercurial/context.py Mon Dec 09 00:01:03 2024 -0500 +++ b/mercurial/context.py Mon Dec 09 00:21:38 2024 -0500 @@ -37,6 +37,9 @@ testing, util, ) +from .interfaces import ( + status as istatus, +) from .utils import ( dateutil, stringutil, @@ -99,7 +102,7 @@ def _buildstatus( self, other, s, match, listignored, listclean, listunknown - ): + ) -> istatus.Status: """build a status with respect to another context""" # Load earliest manifest first for caching reasons. More specifically, # if you have revisions 1000 and 1001, 1001 is probably stored as a @@ -388,7 +391,7 @@ listclean=False, listunknown=False, listsubrepos=False, - ): + ) -> istatus.Status: """return status of files between two nodes or node and working directory. @@ -1905,7 +1908,9 @@ # Even if the wlock couldn't be grabbed, clear out the list. self._repo.clearpostdsstatus() - def _dirstatestatus(self, match, ignored=False, clean=False, unknown=False): + def _dirstatestatus( + self, match, ignored=False, clean=False, unknown=False + ) -> istatus.Status: '''Gets the status from the dirstate -- internal use only.''' subrepos = [] if b'.hgsub' in self: @@ -2729,7 +2734,9 @@ repo, text, user, date, extra, changes ) - def _dirstatestatus(self, match, ignored=False, clean=False, unknown=False): + def _dirstatestatus( + self, match, ignored=False, clean=False, unknown=False + ) -> istatus.Status: """Return matched files only in ``self._status`` Uncommitted files appear "clean" via this context, even if @@ -2924,7 +2931,7 @@ return man @propertycache - def _status(self): + def _status(self) -> istatus.Status: """Calculate exact status from ``files`` specified at construction""" man1 = self.p1().manifest() p2 = self._parents[1] @@ -3089,7 +3096,7 @@ return self._originalctx.manifest() @propertycache - def _status(self): + def _status(self) -> istatus.Status: """Calculate exact status from ``files`` specified in the ``origctx`` and parents manifests. """
--- a/mercurial/interfaces/dirstate.py Mon Dec 09 00:01:03 2024 -0500 +++ b/mercurial/interfaces/dirstate.py Mon Dec 09 00:21:38 2024 -0500 @@ -22,10 +22,11 @@ # to avoid circular imports from .. import ( match as matchmod, - scmutil, transaction as txnmod, ) + from . import status as istatus + # TODO: finish adding type hints AddParentChangeCallbackT = Callable[ ["idirstate", Tuple[Any, Any], Tuple[Any, Any]], Any @@ -49,7 +50,7 @@ """The return type of dirstate.flagfunc().""" # TODO: verify and complete this- it came from a pytype *.pyi file - StatusReturnT = Tuple[Any, scmutil.status, Any] + StatusReturnT = Tuple[Any, istatus.Status, Any] """The return type of dirstate.status().""" # TODO: probably doesn't belong here.
--- a/mercurial/subrepo.py Mon Dec 09 00:01:03 2024 -0500 +++ b/mercurial/subrepo.py Mon Dec 09 00:21:38 2024 -0500 @@ -39,6 +39,9 @@ util, vfs as vfsmod, ) +from .interfaces import ( + status as istatus, +) from .utils import ( dateutil, hashutil, @@ -332,7 +335,7 @@ def cat(self, match, fm, fntemplate, prefix, **opts): return 1 - def status(self, rev2, **opts): + def status(self, rev2, **opts) -> istatus.Status: return scmutil.status([], [], [], [], [], [], []) def diff(self, ui, diffopts, node2, match, prefix, **opts): @@ -614,7 +617,7 @@ ) @annotatesubrepoerror - def status(self, rev2, **opts): + def status(self, rev2, **opts) -> istatus.Status: try: rev1 = self._state[1] ctx1 = self._repo[rev1] @@ -1971,7 +1974,7 @@ return 0 @annotatesubrepoerror - def status(self, rev2, **opts): + def status(self, rev2, **opts) -> istatus.Status: rev1 = self._state[1] if self._gitmissing() or not rev1: # if the repo is missing, return no results
--- a/mercurial/subrepoutil.py Mon Dec 09 00:01:03 2024 -0500 +++ b/mercurial/subrepoutil.py Mon Dec 09 00:21:38 2024 -0500 @@ -52,17 +52,17 @@ context, localrepo, match as matchmod, - scmutil, subrepo, ui as uimod, ) + from .interfaces import status as istatus + # keeps pyflakes happy assert [ context, localrepo, matchmod, - scmutil, subrepo, uimod, ] @@ -334,7 +334,7 @@ def precommit( ui: "uimod.ui", wctx: "context.workingcommitctx", - status: "scmutil.status", + status: "istatus.Status", match: "matchmod.basematcher", force: bool = False, ) -> Tuple[List[bytes], Set[bytes], Substate]: