diff --git a/pygit2/callbacks.py b/pygit2/callbacks.py index 25514764..57e3d773 100644 --- a/pygit2/callbacks.py +++ b/pygit2/callbacks.py @@ -82,12 +82,12 @@ class Payload: - def __init__(self, **kw): + def __init__(self, **kw: object): for key, value in kw.items(): setattr(self, key, value) self._stored_exception = None - def check_error(self, error_code): + def check_error(self, error_code: int) -> None: if error_code == C.GIT_EUSER: assert self._stored_exception is not None raise self._stored_exception @@ -120,7 +120,7 @@ def __init__(self, credentials=None, certificate_check=None): if certificate_check is not None: self.certificate_check = certificate_check - def sideband_progress(self, string): + def sideband_progress(self, string: str) -> None: """ Progress output callback. Override this function with your own progress reporting function @@ -159,7 +159,7 @@ def credentials( """ raise Passthrough - def certificate_check(self, certificate, valid, host): + def certificate_check(self, certificate: None, valid: bool, host: str) -> bool: """ Certificate callback. Override with your own function to determine whether to accept the server's certificate. diff --git a/pygit2/credentials.py b/pygit2/credentials.py index 7b047e46..9a09db76 100644 --- a/pygit2/credentials.py +++ b/pygit2/credentials.py @@ -23,9 +23,17 @@ # the Free Software Foundation, 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. +from __future__ import annotations + +from typing import TYPE_CHECKING + from .enums import CredentialType +if TYPE_CHECKING: + from pathlib import Path + + class Username: """Username credentials @@ -33,7 +41,7 @@ class Username: callback and for returning from said callback. """ - def __init__(self, username): + def __init__(self, username: str): self._username = username @property @@ -44,7 +52,9 @@ def credential_type(self) -> CredentialType: def credential_tuple(self): return (self._username,) - def __call__(self, _url, _username, _allowed): + def __call__( + self, _url: str, _username: str | None, _allowed: CredentialType + ) -> Username: return self @@ -55,7 +65,7 @@ class UserPass: callback and for returning from said callback. """ - def __init__(self, username, password): + def __init__(self, username: str, password: str): self._username = username self._password = password @@ -67,7 +77,9 @@ def credential_type(self) -> CredentialType: def credential_tuple(self): return (self._username, self._password) - def __call__(self, _url, _username, _allowed): + def __call__( + self, _url: str, _username: str | None, _allowed: CredentialType + ) -> UserPass: return self @@ -94,7 +106,9 @@ class Keypair: no passphrase is required. """ - def __init__(self, username, pubkey, privkey, passphrase): + def __init__( + self, username: str, pubkey: str | Path, privkey: str | Path, passphrase: str + ): self._username = username self._pubkey = pubkey self._privkey = privkey @@ -108,12 +122,14 @@ def credential_type(self) -> CredentialType: def credential_tuple(self): return (self._username, self._pubkey, self._privkey, self._passphrase) - def __call__(self, _url, _username, _allowed): + def __call__( + self, _url: str, _username: str | None, _allowed: CredentialType + ) -> Keypair: return self class KeypairFromAgent(Keypair): - def __init__(self, username): + def __init__(self, username: str): super().__init__(username, None, None, None) diff --git a/pygit2/remotes.py b/pygit2/remotes.py index d2fe5142..30c2e5bd 100644 --- a/pygit2/remotes.py +++ b/pygit2/remotes.py @@ -335,7 +335,7 @@ def names(self): for name in self._ffi_names(): yield maybe_string(name) - def create(self, name, url, fetch=None): + def create(self, name, url, fetch=None) -> Remote: """Create a new remote with the given name and url. Returns a <Remote> object.