Mercurial > public > mercurial-scm > hg-stable
changeset 52908:180591a9a6a1
typing: add a protocol for `urlutil.path`
That is the last external import for the repository interface module.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 10 Feb 2025 00:16:22 +0100 |
parents | ba343f763595 |
children | 4fa0d89d1bdb |
files | mercurial/interfaces/misc.py mercurial/utils/urlutil.py |
diffstat | 2 files changed, 45 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/interfaces/misc.py Mon Feb 10 00:15:22 2025 +0100 +++ b/mercurial/interfaces/misc.py Mon Feb 10 00:16:22 2025 +0100 @@ -7,6 +7,7 @@ from typing import ( Callable, + Dict, Iterator, List, Optional, @@ -108,3 +109,41 @@ @abc.abstractmethod def islocal(self) -> bool: ... + + +class IPath(Protocol): + """Represents an individual path and its configuration.""" + + name: bytes + main_path: Optional[IPath] + url: IUrl + raw_url: IUrl + branch: bytes + rawloc: bytes + loc: bytes + + @abc.abstractmethod + def copy(self, new_raw_location: Optional[bytes] = None) -> IPath: + ... + + @property + @abc.abstractmethod + def is_push_variant(self) -> bool: + """is this a path variant to be used for pushing""" + + @abc.abstractmethod + def get_push_variant(self) -> IPath: + """get a "copy" of the path, but suitable for pushing + + This means using the value of the `pushurl` option (if any) as the url. + + The original path is available in the `main_path` attribute. + """ + + @property + @abc.abstractmethod + def suboptions(self) -> Dict[bytes, bytes]: + """Return sub-options and their values for this path. + + This is intended to be used for presentation purposes. + """
--- a/mercurial/utils/urlutil.py Mon Feb 10 00:15:22 2025 +0100 +++ b/mercurial/utils/urlutil.py Mon Feb 10 00:16:22 2025 +0100 @@ -14,6 +14,7 @@ from typing import ( Callable, Dict, + Optional, Tuple, Union, ) @@ -825,7 +826,7 @@ return new_paths -class path: +class path(int_misc.IPath): """Represents an individual path and its configuration.""" def __init__( @@ -892,7 +893,7 @@ self.rawloc = rawloc self.loc = b'%s' % u - def copy(self, new_raw_location=None): + def copy(self, new_raw_location: Optional[bytes] = None) -> path: """make a copy of this path object When `new_raw_location` is set, the new path will point to it. @@ -909,11 +910,11 @@ return new @property - def is_push_variant(self): + def is_push_variant(self) -> bool: """is this a path variant to be used for pushing""" return self.main_path is not None - def get_push_variant(self): + def get_push_variant(self) -> path: """get a "copy" of the path, but suitable for pushing This means using the value of the `pushurl` option (if any) as the url. @@ -965,7 +966,7 @@ return False @property - def suboptions(self): + def suboptions(self) -> Dict[bytes, bytes]: """Return sub-options and their values for this path. This is intended to be used for presentation purposes.