Mercurial > public > mercurial-scm > hg
diff mercurial/context.py @ 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 | f4733654f144 |
children | 24ee91ba9aa8 |
line wrap: on
line diff
--- 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. """