Skip to content

Commit

Permalink
More typing
Browse files Browse the repository at this point in the history
  • Loading branch information
sathieu committed Jan 28, 2025
1 parent ff414d5 commit 43e851f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
8 changes: 4 additions & 4 deletions pygit2/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Progress output callback. Override this function with your own
progress reporting function
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 9 additions & 7 deletions pygit2/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.

from __future__ import annotations

from .ffi import C

from .enums import CredentialType
Expand All @@ -35,7 +37,7 @@ class Username:
callback and for returning from said callback.
"""

def __init__(self, username):
def __init__(self, username: str):
self._username = username

@property
Expand All @@ -46,7 +48,7 @@ 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


Expand All @@ -57,7 +59,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

Expand All @@ -69,7 +71,7 @@ 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


Expand All @@ -96,7 +98,7 @@ class Keypair:
no passphrase is required.
"""

def __init__(self, username, pubkey, privkey, passphrase):
def __init__(self, username: str, pubkey: str, privkey: str, passphrase: str):
self._username = username
self._pubkey = pubkey
self._privkey = privkey
Expand All @@ -110,12 +112,12 @@ 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)


Expand Down
2 changes: 1 addition & 1 deletion pygit2/remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 43e851f

Please sign in to comment.