Skip to content

Commit 3aabbc7

Browse files
committed
add typing to credentials.py
1 parent 7433683 commit 3aabbc7

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

pygit2/credentials.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,19 @@
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 Any, Protocol
29+
2630
from .enums import CredentialType
27-
from .ffi import C
31+
32+
33+
class BaseCredentials(Protocol):
34+
@property
35+
def credential_type(self) -> CredentialType: ...
36+
@property
37+
def credential_tuple(self) -> tuple[str, ...]: ...
38+
def __call__(self, _url: Any, _username: Any, _allowed: Any) -> BaseCredentials: ...
2839

2940

3041
class Username:
@@ -34,7 +45,7 @@ class Username:
3445
callback and for returning from said callback.
3546
"""
3647

37-
def __init__(self, username):
48+
def __init__(self, username: str):
3849
self._username = username
3950

4051
@property
@@ -45,7 +56,7 @@ def credential_type(self) -> CredentialType:
4556
def credential_tuple(self):
4657
return (self._username,)
4758

48-
def __call__(self, _url, _username, _allowed):
59+
def __call__(self, _url: Any, _username: Any, _allowed: Any):
4960
return self
5061

5162

@@ -56,7 +67,7 @@ class UserPass:
5667
callback and for returning from said callback.
5768
"""
5869

59-
def __init__(self, username, password):
70+
def __init__(self, username: str, password: str):
6071
self._username = username
6172
self._password = password
6273

@@ -68,7 +79,7 @@ def credential_type(self) -> CredentialType:
6879
def credential_tuple(self):
6980
return (self._username, self._password)
7081

71-
def __call__(self, _url, _username, _allowed):
82+
def __call__(self, _url: Any, _username: Any, _allowed: Any):
7283
return self
7384

7485

@@ -95,7 +106,13 @@ class Keypair:
95106
no passphrase is required.
96107
"""
97108

98-
def __init__(self, username, pubkey, privkey, passphrase):
109+
def __init__(
110+
self,
111+
username: str,
112+
pubkey: str | None,
113+
privkey: str | None,
114+
passphrase: str | None,
115+
):
99116
self._username = username
100117
self._pubkey = pubkey
101118
self._privkey = privkey
@@ -109,12 +126,12 @@ def credential_type(self) -> CredentialType:
109126
def credential_tuple(self):
110127
return (self._username, self._pubkey, self._privkey, self._passphrase)
111128

112-
def __call__(self, _url, _username, _allowed):
129+
def __call__(self, _url: Any, _username: Any, _allowed: Any):
113130
return self
114131

115132

116133
class KeypairFromAgent(Keypair):
117-
def __init__(self, username):
134+
def __init__(self, username: str):
118135
super().__init__(username, None, None, None)
119136

120137

0 commit comments

Comments
 (0)