Skip to content

Commit d35ab54

Browse files
committed
More typing
1 parent eba0249 commit d35ab54

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

pygit2/callbacks.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@
8282

8383

8484
class Payload:
85-
def __init__(self, **kw):
85+
def __init__(self, **kw: object):
8686
for key, value in kw.items():
8787
setattr(self, key, value)
8888
self._stored_exception = None
8989

90-
def check_error(self, error_code):
90+
def check_error(self, error_code: int) -> None:
9191
if error_code == C.GIT_EUSER:
9292
assert self._stored_exception is not None
9393
raise self._stored_exception
@@ -120,7 +120,7 @@ def __init__(self, credentials=None, certificate_check=None):
120120
if certificate_check is not None:
121121
self.certificate_check = certificate_check
122122

123-
def sideband_progress(self, string):
123+
def sideband_progress(self, string: str) -> None:
124124
"""
125125
Progress output callback. Override this function with your own
126126
progress reporting function
@@ -159,7 +159,7 @@ def credentials(
159159
"""
160160
raise Passthrough
161161

162-
def certificate_check(self, certificate, valid, host):
162+
def certificate_check(self, certificate: None, valid: bool, host: str) -> bool:
163163
"""
164164
Certificate callback. Override with your own function to determine
165165
whether to accept the server's certificate.

pygit2/credentials.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,24 @@
2323
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
2424
# Boston, MA 02110-1301, USA.
2525

26+
from __future__ import annotations
27+
28+
from typing import TYPE_CHECKING
29+
2630
from .enums import CredentialType
2731

2832

33+
if TYPE_CHECKING:
34+
from pathlib import Path
35+
2936
class Username:
3037
"""Username credentials
3138
3239
This is an object suitable for passing to a remote's credentials
3340
callback and for returning from said callback.
3441
"""
3542

36-
def __init__(self, username):
43+
def __init__(self, username: str):
3744
self._username = username
3845

3946
@property
@@ -44,7 +51,9 @@ def credential_type(self) -> CredentialType:
4451
def credential_tuple(self):
4552
return (self._username,)
4653

47-
def __call__(self, _url, _username, _allowed):
54+
def __call__(
55+
self, _url: str, _username: str | None, _allowed: CredentialType
56+
) -> Username:
4857
return self
4958

5059

@@ -55,7 +64,7 @@ class UserPass:
5564
callback and for returning from said callback.
5665
"""
5766

58-
def __init__(self, username, password):
67+
def __init__(self, username: str, password: str):
5968
self._username = username
6069
self._password = password
6170

@@ -67,7 +76,9 @@ def credential_type(self) -> CredentialType:
6776
def credential_tuple(self):
6877
return (self._username, self._password)
6978

70-
def __call__(self, _url, _username, _allowed):
79+
def __call__(
80+
self, _url: str, _username: str | None, _allowed: CredentialType
81+
) -> UserPass:
7182
return self
7283

7384

@@ -94,7 +105,7 @@ class Keypair:
94105
no passphrase is required.
95106
"""
96107

97-
def __init__(self, username, pubkey, privkey, passphrase):
108+
def __init__(self, username: str, pubkey: str | Path, privkey: str | Path, passphrase: str):
98109
self._username = username
99110
self._pubkey = pubkey
100111
self._privkey = privkey
@@ -108,12 +119,14 @@ def credential_type(self) -> CredentialType:
108119
def credential_tuple(self):
109120
return (self._username, self._pubkey, self._privkey, self._passphrase)
110121

111-
def __call__(self, _url, _username, _allowed):
122+
def __call__(
123+
self, _url: str, _username: str | None, _allowed: CredentialType
124+
) -> Keypair:
112125
return self
113126

114127

115128
class KeypairFromAgent(Keypair):
116-
def __init__(self, username):
129+
def __init__(self, username: str):
117130
super().__init__(username, None, None, None)
118131

119132

pygit2/remotes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def names(self):
335335
for name in self._ffi_names():
336336
yield maybe_string(name)
337337

338-
def create(self, name, url, fetch=None):
338+
def create(self, name, url, fetch=None) -> Remote:
339339
"""Create a new remote with the given name and url. Returns a <Remote>
340340
object.
341341

0 commit comments

Comments
 (0)