Mercurial > public > mercurial-scm > hg-stable
changeset 52906:bde94bd8e8a2
typing: use a protocol to annotate `pathutil.dirs` in repository.py
That is one external import for the repository interface module. One more to go.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sat, 08 Feb 2025 18:15:18 +0100 |
parents | 483b0bb23085 |
children | ba343f763595 |
files | mercurial/interfaces/misc.py mercurial/interfaces/repository.py mercurial/pathutil.py |
diffstat | 3 files changed, 25 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/interfaces/misc.py Sat Feb 08 18:12:29 2025 +0100 +++ b/mercurial/interfaces/misc.py Sat Feb 08 18:15:18 2025 +0100 @@ -7,6 +7,7 @@ from typing import ( Callable, + Iterator, List, Protocol, ) @@ -24,3 +25,23 @@ @abc.abstractmethod def __call__(self, *args) -> List: ... + + +class IDirs(Protocol): + '''a multiset of directory names from a set of file paths''' + + @abc.abstractmethod + def addpath(self, path: bytes) -> None: + ... + + @abc.abstractmethod + def delpath(self, path: bytes) -> None: + ... + + @abc.abstractmethod + def __iter__(self) -> Iterator[bytes]: + ... + + @abc.abstractmethod + def __contains__(self, d: bytes) -> bool: + ...
--- a/mercurial/interfaces/repository.py Sat Feb 08 18:12:29 2025 +0100 +++ b/mercurial/interfaces/repository.py Sat Feb 08 18:15:18 2025 +0100 @@ -31,9 +31,6 @@ # Almost all mercurial modules are only imported in the type checking phase # to avoid circular imports - from .. import ( - pathutil, - ) from ..utils import ( urlutil, ) @@ -1178,7 +1175,7 @@ """ @abc.abstractmethod - def dirs(self) -> pathutil.dirs: + def dirs(self) -> misc.IDirs: """Returns an object implementing the ``idirs`` interface.""" @abc.abstractmethod
--- a/mercurial/pathutil.py Sat Feb 08 18:12:29 2025 +0100 +++ b/mercurial/pathutil.py Sat Feb 08 18:15:18 2025 +0100 @@ -22,6 +22,8 @@ util, ) +from .interfaces import misc as int_misc + rustdirs = policy.importrust('dirstate', 'Dirs', pyo3=True) parsers = policy.importmod('parsers') @@ -335,7 +337,7 @@ pos = path.find(pycompat.ossep, pos + 1) -class dirs: +class dirs(int_misc.IDirs): '''a multiset of directory names from a set of file paths''' def __init__(self, map, only_tracked=False):