# HG changeset patch # User Matt Harbison # Date 2024-12-16 06:55:41 # Node ID 5a924cb07768946f09a38f3bad772ee8fef6f653 # Parent 700086cf336d4b03cadc86024de15211fde750d6 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. diff --git a/mercurial/interfaces/repository.py b/mercurial/interfaces/repository.py --- a/mercurial/interfaces/repository.py +++ b/mercurial/interfaces/repository.py @@ -193,7 +193,7 @@ class ipeercapabilities(Protocol): """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 @@ class ipeercapabilities(Protocol): """ @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 @@ class peer(_ipeerconnection, ipeercapabi """ 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 @@ class peer(_ipeerconnection, ipeercapabi return False - def requirecap(self, name, purpose): + def requirecap(self, name: bytes, purpose: bytes) -> None: if self.capable(name): return