view mercurial/interfaces/status.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 f5d134e57f51
children
line wrap: on
line source

# 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

import abc

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."""

    @abc.abstractmethod
    def __iter__(self) -> Iterator[list[bytes]]:
        """Iterates over each of the categories of file lists."""

    @abc.abstractmethod
    def __repr__(self) -> str:
        """Creates a string representation of the file lists."""