# HG changeset patch # User Matt Harbison # Date 1733719932 18000 # Node ID a1c0f19e7cb4a9cfbefc108d37dea471270a0287 # Parent 1df193f1515e87f156a7a1c5839686ad6bc4e0a1 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. diff -r 1df193f1515e -r a1c0f19e7cb4 mercurial/interfaces/status.py --- /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 +# +# 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."""