Skip to content

Commit ba30d56

Browse files
committed
More typing
1 parent ff414d5 commit ba30d56

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-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):
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

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

26+
from __future__ import annotations
27+
2628
from .ffi import C
2729

2830
from .enums import CredentialType
@@ -35,7 +37,7 @@ class Username:
3537
callback and for returning from said callback.
3638
"""
3739

38-
def __init__(self, username):
40+
def __init__(self, username: str):
3941
self._username = username
4042

4143
@property
@@ -46,7 +48,9 @@ def credential_type(self) -> CredentialType:
4648
def credential_tuple(self):
4749
return (self._username,)
4850

49-
def __call__(self, _url, _username, _allowed):
51+
def __call__(
52+
self, _url: str, _username: str | None, _allowed: CredentialType
53+
) -> Username:
5054
return self
5155

5256

@@ -57,7 +61,7 @@ class UserPass:
5761
callback and for returning from said callback.
5862
"""
5963

60-
def __init__(self, username, password):
64+
def __init__(self, username: str, password: str):
6165
self._username = username
6266
self._password = password
6367

@@ -69,7 +73,9 @@ def credential_type(self) -> CredentialType:
6973
def credential_tuple(self):
7074
return (self._username, self._password)
7175

72-
def __call__(self, _url, _username, _allowed):
76+
def __call__(
77+
self, _url: str, _username: str | None, _allowed: CredentialType
78+
) -> UserPass:
7379
return self
7480

7581

@@ -96,7 +102,7 @@ class Keypair:
96102
no passphrase is required.
97103
"""
98104

99-
def __init__(self, username, pubkey, privkey, passphrase):
105+
def __init__(self, username: str, pubkey: str, privkey: str, passphrase: str):
100106
self._username = username
101107
self._pubkey = pubkey
102108
self._privkey = privkey
@@ -110,12 +116,14 @@ def credential_type(self) -> CredentialType:
110116
def credential_tuple(self):
111117
return (self._username, self._pubkey, self._privkey, self._passphrase)
112118

113-
def __call__(self, _url, _username, _allowed):
119+
def __call__(
120+
self, _url: str, _username: str | None, _allowed: CredentialType
121+
) -> Keypair:
114122
return self
115123

116124

117125
class KeypairFromAgent(Keypair):
118-
def __init__(self, username):
126+
def __init__(self, username: str):
119127
super().__init__(username, None, None, None)
120128

121129

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)