Skip to content

Commit 6a4192a

Browse files
committed
More typing
1 parent eba0249 commit 6a4192a

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-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

+23-7
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,25 @@
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+
36+
2937
class Username:
3038
"""Username credentials
3139
3240
This is an object suitable for passing to a remote's credentials
3341
callback and for returning from said callback.
3442
"""
3543

36-
def __init__(self, username):
44+
def __init__(self, username: str):
3745
self._username = username
3846

3947
@property
@@ -44,7 +52,9 @@ def credential_type(self) -> CredentialType:
4452
def credential_tuple(self):
4553
return (self._username,)
4654

47-
def __call__(self, _url, _username, _allowed):
55+
def __call__(
56+
self, _url: str, _username: str | None, _allowed: CredentialType
57+
) -> Username:
4858
return self
4959

5060

@@ -55,7 +65,7 @@ class UserPass:
5565
callback and for returning from said callback.
5666
"""
5767

58-
def __init__(self, username, password):
68+
def __init__(self, username: str, password: str):
5969
self._username = username
6070
self._password = password
6171

@@ -67,7 +77,9 @@ def credential_type(self) -> CredentialType:
6777
def credential_tuple(self):
6878
return (self._username, self._password)
6979

70-
def __call__(self, _url, _username, _allowed):
80+
def __call__(
81+
self, _url: str, _username: str | None, _allowed: CredentialType
82+
) -> UserPass:
7183
return self
7284

7385

@@ -94,7 +106,9 @@ class Keypair:
94106
no passphrase is required.
95107
"""
96108

97-
def __init__(self, username, pubkey, privkey, passphrase):
109+
def __init__(
110+
self, username: str, pubkey: str | Path, privkey: str | Path, passphrase: str
111+
):
98112
self._username = username
99113
self._pubkey = pubkey
100114
self._privkey = privkey
@@ -108,12 +122,14 @@ def credential_type(self) -> CredentialType:
108122
def credential_tuple(self):
109123
return (self._username, self._pubkey, self._privkey, self._passphrase)
110124

111-
def __call__(self, _url, _username, _allowed):
125+
def __call__(
126+
self, _url: str, _username: str | None, _allowed: CredentialType
127+
) -> Keypair:
112128
return self
113129

114130

115131
class KeypairFromAgent(Keypair):
116-
def __init__(self, username):
132+
def __init__(self, username: str):
117133
super().__init__(username, None, None, None)
118134

119135

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)