Mercurial > public > mercurial-scm > hg-stable
changeset 52545:5a924cb07768
typing: add annotations to the `repository.peer` mixin class
This was done investigating 199b0e62b403.
AFAICT, the `path` is always a `urlutil.path`, and pytype complained when I
first assumed it was bytes. `hg.peer()` also converts possible string input to
this class. But in making it `urlutil.path`, PyCharm now flags `debugwireproto`
because it passes bytes to `sshpeer.sshv1peer()`, and we do have test coverage
for that command. Curious.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 16 Dec 2024 01:55:41 -0500 |
parents | 700086cf336d |
children | 5cf81d8d7de1 |
files | mercurial/interfaces/repository.py |
diffstat | 1 files changed, 13 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/interfaces/repository.py Mon Dec 16 01:52:32 2024 -0500 +++ b/mercurial/interfaces/repository.py Mon Dec 16 01:55:41 2024 -0500 @@ -193,7 +193,7 @@ """Peer sub-interface related to capabilities.""" @abc.abstractmethod - def capable(self, name): + def capable(self, name: bytes) -> bool | bytes: """Determine support for a named capability. Returns ``False`` if capability not supported. @@ -205,7 +205,7 @@ """ @abc.abstractmethod - def requirecap(self, name, purpose): + def requirecap(self, name: bytes, purpose: bytes) -> None: """Require a capability to be present. Raises a ``CapabilityError`` if the capability isn't present. @@ -457,12 +457,19 @@ """ limitedarguments: bool = False - - def __init__(self, ui, path=None, remotehidden=False): + path: urlutil.path | None + ui: Ui + + def __init__( + self, + ui: Ui, + path: urlutil.path | None = None, + remotehidden: bool = False, + ) -> None: self.ui = ui self.path = path - def capable(self, name): + def capable(self, name: bytes) -> bool | bytes: # TODO: this class should maybe subclass ipeercommands too, otherwise it # is assuming whatever uses this as a mixin also has this interface. caps = self.capabilities() # pytype: disable=attribute-error @@ -476,7 +483,7 @@ return False - def requirecap(self, name, purpose): + def requirecap(self, name: bytes, purpose: bytes) -> None: if self.capable(name): return