Mercurial > public > mercurial-scm > hg-stable
changeset 52479:a1c0f19e7cb4
interfaces: add a Protocol class for `scmutil.status`
I initially tried moving this to the `interfaces` package, both to have more
cleanly defined interfaces (interfaces shouldn't have to reach into
implementation files for their type info), and because importing `mercurial.ui`
either directly or indirectly into `interfaces.repository` causes a situation
where pytype stops inferring the type for `revlogutils.constants` that are
imported by `revlog`. (Likely this is caused by a cycle. The `dirstate`
interface already imports `scmutil`, which in turn imports `ui`, so the
`repository` interface module importing the `dirstate` interface module as part
of converting those classes to Protocol classes will trigger the issue.)
I gave up on moving the class because `scmutil.status` depends on `stringutil`,
which has a surprisingly long tail of dependencies. In any event, a standalone
Protocol class might help with the Rust code.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 08 Dec 2024 23:52:12 -0500 |
parents | 1df193f1515e |
children | f5d134e57f51 |
files | mercurial/interfaces/status.py |
diffstat | 1 files changed, 49 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial/interfaces/status.py Sun Dec 08 23:52:12 2024 -0500 @@ -0,0 +1,49 @@ +# status.py - Type annotations for status related objects +# +# Copyright Matt Harbison <mharbison72@gmail.com> +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2 or any later version. + +from __future__ import annotations + +from typing import ( + Iterator, + Protocol, +) + + +class Status(Protocol): + """Struct with a list of files per status. + + The 'deleted', 'unknown' and 'ignored' properties are only + relevant to the working copy. + """ + + modified: list[bytes] + """The list of files with modifications.""" + + added: list[bytes] + """The list of files that started being tracked.""" + + removed: list[bytes] + """The list of files that stopped being tracked.""" + + deleted: list[bytes] + """The list of files in the working directory that are deleted from the + file system (but not in the removed state).""" + + unknown: list[bytes] + """The list of files in the working directory that are not tracked.""" + + ignored: list[bytes] + """The list of files in the working directory that are ignored.""" + + clean: list[bytes] + """The list of files that are not in any other state.""" + + def __iter__(self) -> Iterator[list[bytes]]: + """Iterates over each of the categories of file lists.""" + + def __repr__(self) -> str: + """Creates a string representation of the file lists."""